-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcmdline.sh
More file actions
executable file
·129 lines (108 loc) · 4.95 KB
/
cmdline.sh
File metadata and controls
executable file
·129 lines (108 loc) · 4.95 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2016 ale5000
# SPDX-License-Identifier: GPL-3.0-or-later
# shellcheck enable=all
# Workaround for shells without support for local (example: ksh pbosh obosh)
command 1> /dev/null 2>&1 -v 'local' || {
eval ' local() { :; } ' || :
# On some variants of ksh this really works, but leave the function as dummy fallback
if command 1> /dev/null 2>&1 -v 'typeset'; then alias 'local'='typeset'; fi
}
if test "${A5K_FUNCTIONS_INCLUDED:-false}" = 'false'; then
main()
{
local _main_dir _run_strategy _applet _uname_os _nl
# Execute only if the first initialization has not already been done
if test -z "${MAIN_DIR-}" || test -z "${USER_HOME-}"; then
# Avoid picturesque bugs on Bash under Windows
if test -x '/usr/bin/uname' && _uname_os="$(/usr/bin/uname 2> /dev/null -o)" && test "${_uname_os}" = 'Msys'; then PATH="/usr/bin:${PATH:-%empty}"; fi
if test -z "${MAIN_DIR-}"; then
# shellcheck disable=SC3028,SC2128 # Intended: In POSIX sh, BASH_SOURCE is undefined / Expanding an array without an index only gives the first element
if MAIN_DIR="${BASH_SOURCE-}" && test -n "${MAIN_DIR}"; then :; else MAIN_DIR="${1}"; fi
case "${MAIN_DIR}" in *'cmdline.sh') ;; *) MAIN_DIR='' ;; esac
if test -n "${MAIN_DIR}" && MAIN_DIR="$(dirname "${MAIN_DIR}")" && MAIN_DIR="$(realpath "${MAIN_DIR}")"; then export MAIN_DIR; else unset MAIN_DIR; fi
fi
if test -n "${MAIN_DIR-}" && test -z "${USER_HOME-}"; then
if test "${TERM_PROGRAM-}" = 'mintty'; then TERM_PROGRAM='mintty-'; fi
export USER_HOME="${HOME-}"
export HOME="${MAIN_DIR}"
fi
fi
shift
get_shell_exe()
{
local _gse_shell_exe _gse_tmp_var
if _gse_shell_exe="$(readlink 2> /dev/null "/proc/${$}/exe")" && test -n "${_gse_shell_exe}"; then
# On Linux / Android / Windows (on Windows only some shells support it)
printf '%s\n' "${_gse_shell_exe}"
return 0
elif _gse_tmp_var="$(ps 2> /dev/null -p "${$}" -o 'comm=')" && test -n "${_gse_tmp_var}" && _gse_tmp_var="$(command 2> /dev/null -v "${_gse_tmp_var}")"; then
# On Linux / macOS
# shellcheck disable=SC2230 # Ignore: 'which' is non-standard
case "${_gse_tmp_var}" in *'/'* | *"\\"*) ;; *) _gse_tmp_var="$(which 2> /dev/null "${_gse_tmp_var}")" || return 3 ;; esac # We may not get the full path with "command -v" on some old versions of Oils
elif _gse_tmp_var="${BASH:-${SHELL-}}" && test -n "${_gse_tmp_var}"; then
if test "${_gse_tmp_var}" = '/bin/sh' && test "$(uname 2> /dev/null || :)" = 'Windows_NT'; then _gse_tmp_var="$(command 2> /dev/null -v 'busybox')" || return 2; fi
if test ! -x "${_gse_tmp_var}" && test -x "${_gse_tmp_var}.exe"; then _gse_tmp_var="${_gse_tmp_var}.exe"; fi # Special fix for broken versions of Bash under Windows
else
return 1
fi
_gse_shell_exe="$(readlink 2> /dev/null -f "${_gse_tmp_var}" || realpath 2> /dev/null "${_gse_tmp_var}")" || _gse_shell_exe="${_gse_tmp_var}"
printf '%s\n' "${_gse_shell_exe}"
return 0
}
__SHELL_EXE="$(get_shell_exe)" || __SHELL_EXE='bash'
export __SHELL_EXE
unset _gse_shell_exe _gse_tmp_var
_run_strategy='init-file'
_applet=''
case "${__SHELL_EXE}" in
*'/busybox'*) # BusyBox
_run_strategy='s-opt'
_applet="${CUSTOM_APPLET:-ash}"
;;
*'/oil.ovm' | *'/oils-for-unix') # Oils
_run_strategy='source'
_applet="${CUSTOM_APPLET:-osh}"
;;
*'/osh') # Oils
_run_strategy='source'
;;
*) ;;
esac
if test -n "${MAIN_DIR-}"; then _main_dir="${MAIN_DIR}"; else _main_dir='.'; fi
if test "${ONLY_FOR_TESTING-}" = 'true'; then
printf '%s\n' "${__SHELL_EXE}"
printf '%s\n' "${_main_dir}"
_run_strategy='source'
fi
export DO_INIT_CMDLINE=1
unset KILL_PPID
unset STARTED_FROM_BATCH_FILE
unset IS_PATH_INITIALIZED
unset __QUOTED_PARAMS
if test "${_run_strategy}" = 'source'; then
. "${_main_dir}/lib/common.lib.sh" "${@}" || return "${?}"
elif test "${_run_strategy}" = 's-opt'; then
# shellcheck disable=SC2086 # Ignore: Double quote to prevent globbing and word splitting
exec "${__SHELL_EXE}" ${_applet} -s -c ". '${_main_dir}/lib/common.lib.sh' || exit \${?}" "${_applet:-${0-}}" "${@}"
else
if test "${#}" -gt 0; then
_nl="$(printf '\nx')" _nl="${_nl%x}"
case "${*}" in
*"${_nl}"*) printf 1>&2 '%s\n' 'WARNING: Newline character found, parameters dropped' ;;
*)
__QUOTED_PARAMS="$(printf '%s\n' "${@}")"
export __QUOTED_PARAMS
;;
esac
fi
# shellcheck disable=SC2086 # Ignore: Double quote to prevent globbing and word splitting
exec "${__SHELL_EXE}" ${_applet} --init-file "${_main_dir}/lib/common.lib.sh"
fi
}
if test "${#}" -gt 0; then
main "${0-}" "${@}"
else
main "${0-}"
fi
fi