shims/utils.sh: repair style

This commit is contained in:
hyuraku 2021-04-18 16:44:53 +09:00
parent 520b8110e8
commit 538c65d6f8

View File

@ -11,7 +11,7 @@ absdir() {
dirbasepath() { dirbasepath() {
local dir="$1" local dir="$1"
local base="${2##*/}" local base="${2##*/}"
echo "$dir/$base" echo "${dir}/${base}"
} }
realpath() { realpath() {
@ -19,28 +19,28 @@ realpath() {
local dir local dir
local dest local dest
dir="$(absdir "$path")" dir="$(absdir "${path}")"
path="$(dirbasepath "$dir" "$path")" path="$(dirbasepath "${dir}" "${path}")"
while [[ -L "$path" ]] while [[ -L "${path}" ]]
do do
dest="$(readlink "$path")" dest="$(readlink "${path}")"
if [[ "$dest" = "/"* ]] if [[ "${dest}" = "/"* ]]
then then
path="$dest" path="${dest}"
else else
path="$dir/$dest" path="${dir}/${dest}"
fi fi
dir="$(absdir "$path")" dir="$(absdir "${path}")"
path="$(dirbasepath "$dir" "$path")" path="$(dirbasepath "${dir}" "${path}")"
done done
echo "$path" echo "${path}"
} }
executable() { executable() {
local file="$1" local file="$1"
[[ -f "$file" && -x "$file" ]] [[ -f "${file}" && -x "${file}" ]]
} }
lowercase() { lowercase() {
@ -49,22 +49,22 @@ lowercase() {
safe_exec() { safe_exec() {
local arg0="$1" local arg0="$1"
if ! executable "$arg0" if ! executable "${arg0}"
then then
return return
fi fi
# prevent fork-bombs # prevent fork-bombs
if [[ "$(lowercase "$arg0")" = "$SHIM_FILE" || "$(realpath "$arg0")" = "$SHIM_REAL" ]] if [[ "$(lowercase "${arg0}")" = "${SHIM_FILE}" || "$(realpath "${arg0}")" = "${SHIM_REAL}" ]]
then then
return return
fi fi
if [[ "$HOMEBREW" = "print-path" ]] if [[ "${HOMEBREW}" = "print-path" ]]
then then
local dir local dir
dir="$(quiet_safe_cd "${arg0%/*}/" && pwd)" dir="$(quiet_safe_cd "${arg0%/*}/" && pwd)"
local path local path
path="$(dirbasepath "$dir" "$arg0")" path="$(dirbasepath "${dir}" "${arg0}")"
echo "$path" echo "${path}"
exit exit
fi fi
exec "$@" exec "$@"
@ -75,11 +75,11 @@ try_exec_non_system() {
shift shift
IFS=$'\n' IFS=$'\n'
for path in $(type -aP "$file") for path in $(type -aP "${file}")
do do
if [[ "$path" != "/usr/bin/$file" ]] if [[ "${path}" != "/usr/bin/${file}" ]]
then then
safe_exec "$path" "$@" safe_exec "${path}" "$@"
fi fi
done done
unset IFS unset IFS