-
Notifications
You must be signed in to change notification settings - Fork 4
/
compatibility.functions
114 lines (92 loc) · 3.15 KB
/
compatibility.functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# This file is part of shellfire core. It is subject to the licence terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/core/master/COPYRIGHT. No part of shellfire core, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2014-2015 The developers of shellfire core. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/core/master/COPYRIGHT.
core_usesIn core functions
core_init_defines core_compatibility_basename
core_init_defines core_compatibility_which
core_init_defines core_compatibility_whichNoOutput
core_compatibility_dirname()
{
local converted="${1%/*}"
if [ "$converted" = "$1" ]; then
printf '%s' '.'
else
printf '%s' "$converted"
fi
}
_core_compatibility_builtInDoesNotExist()
{
local builtInName="$1"
local value="$(PATH='' core_compatibility_which "$builtInName")"
if [ "$builtInName" = "$value" ]; then
return 1
fi
return 0
}
# dash by default escapes backslashes, other echos behave differently. This way is defensive.
core_compatibility_echo()
{
printf '%s\n' "$1"
}
core_dependency_requires '*' sleep
core_compatibility_sleepSupportsFractionalSeconds()
{
sleep 0.0001 2>/dev/null
}
core_usesIn core functions
core_compatibility_execute()
{
core_functions_execute _core_compatibility_functions
}
core_compatibility_setSaneShellOptions()
{
:
}
core_functions_register _core_compatibility_functions core_compatibility_setSaneShellOptions
core_compability_installPushdAndPopd()
{
# bash, zsh are known to support this
if _core_compatibility_builtInDoesNotExist pushd; then
if ! _core_compatibility_builtInDoesNotExist popd; then
core_exitError $core_commandLine_exitCode_SOFTWARE "Weird shell does not have pushd but does have popd (?feature detection bug?)!"
fi
_core_init_compatibility_pushdCount=0
pushd()
{
local path="$1"
eval "core_init_pushdStack${_core_init_compatibility_pushdCount}='$(pwd)'"
_core_init_compatibility_pushdCount=$((_core_init_compatibility_pushdCount+1))
cd "$path" 1>/dev/null
}
popd()
{
_core_init_compatibility_pushdCount=$((_core_init_compatibility_pushdCount-1))
eval "local path=\"\$core_init_pushdStack${_core_init_compatibility_pushdCount}\""
eval "unset core_init_pushdStack${_core_init_compatibility_pushdCount}"
cd "$path" 1>/dev/null
}
else
pushd()
{
builtin pushd "$@" 1>/dev/null
}
popd()
{
builtin popd "$@" 1>/dev/null
}
fi
}
core_functions_register _core_compatibility_functions core_compability_installPushdAndPopd
core_compability_installSource()
{
# bash, zsh are known to support this
if _core_compatibility_builtInDoesNotExist source; then
# Done using as eval to workaround a bug in BusyBox's ash shell when the 'source' directive is compiled in
# BusyBox's ash parser evaluates this code not at 'if-time' but at evaluation of the surrounding code
# Yuck
eval 'source()
{
. "$@"
}'
fi
}
core_functions_register _core_compatibility_functions core_compability_installSource