fix(ci): run shfmt
the ci requires that you run `shfmt -w --indent=4 --language-dialect=posix --simplify *.sh'`, and as such, i now have. note: I also formatted the case statement in parse_args to fit on one screen while still being readable.
This commit is contained in:
parent
b242e49ca3
commit
17304135eb
91
install.sh
91
install.sh
|
|
@ -12,17 +12,17 @@
|
||||||
usage() {
|
usage() {
|
||||||
# Note: here-docs aren't defined in posix
|
# Note: here-docs aren't defined in posix
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
"Usage: install.sh [option]" \
|
"Usage: install.sh [option]" \
|
||||||
"Fetch and install the latest version of zoxide, if zoxide is already" \
|
"Fetch and install the latest version of zoxide, if zoxide is already" \
|
||||||
"installed it will be updated to the latest version." \
|
"installed it will be updated to the latest version." \
|
||||||
"" \
|
"" \
|
||||||
"Options:" \
|
"Options:" \
|
||||||
" -b, --bin-dir Override the bin installation directory [default: ${_bin_dir}]" \
|
" -b, --bin-dir Override the bin installation directory [default: ${_bin_dir}]" \
|
||||||
" -m, --man-dir Override the man installation directory [default: ${_man_dir}]" \
|
" -m, --man-dir Override the man installation directory [default: ${_man_dir}]" \
|
||||||
" -a, --arch Override the architecture identified by the installer" \
|
" -a, --arch Override the architecture identified by the installer" \
|
||||||
" -s, --sudo Override the command used to elevate to root privaliges [default: sudo]" \
|
" -s, --sudo Override the command used to elevate to root privaliges [default: sudo]" \
|
||||||
" -h, --help Display this help message" \
|
" -h, --help Display this help message" ||
|
||||||
|| true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
|
@ -64,8 +64,8 @@ main() {
|
||||||
|
|
||||||
local _bin_name
|
local _bin_name
|
||||||
case "${_arch}" in
|
case "${_arch}" in
|
||||||
*windows*) _bin_name="zoxide.exe" ;;
|
*windows*) _bin_name="zoxide.exe" ;;
|
||||||
*) _bin_name="zoxide" ;;
|
*) _bin_name="zoxide" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
local _sudo
|
local _sudo
|
||||||
|
|
@ -81,8 +81,6 @@ main() {
|
||||||
echo "Installing zoxide as root, please wait…"
|
echo "Installing zoxide as root, please wait…"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Create and enter a temporary directory.
|
# Create and enter a temporary directory.
|
||||||
local _tmp_dir
|
local _tmp_dir
|
||||||
_tmp_dir="$(mktemp -d)" || err "mktemp: could not create temporary directory"
|
_tmp_dir="$(mktemp -d)" || err "mktemp: could not create temporary directory"
|
||||||
|
|
@ -128,7 +126,6 @@ main() {
|
||||||
echo "Installing zoxide man pages as root, please wait…"
|
echo "Installing zoxide man pages as root, please wait…"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Install manpages.
|
# Install manpages.
|
||||||
# shellcheck disable=SC2086 # The lack of quoting is intentional.
|
# shellcheck disable=SC2086 # The lack of quoting is intentional.
|
||||||
{
|
{
|
||||||
|
|
@ -137,7 +134,6 @@ main() {
|
||||||
}
|
}
|
||||||
echo "Installed manpages to ${_man_dir}"
|
echo "Installed manpages to ${_man_dir}"
|
||||||
|
|
||||||
|
|
||||||
# Print success message and check $PATH.
|
# Print success message and check $PATH.
|
||||||
echo ""
|
echo ""
|
||||||
echo "zoxide is installed!"
|
echo "zoxide is installed!"
|
||||||
|
|
@ -460,10 +456,10 @@ err() {
|
||||||
|
|
||||||
elevate_priv() {
|
elevate_priv() {
|
||||||
if ! check_cmd sudo; then
|
if ! check_cmd sudo; then
|
||||||
echo 'Could not find the command "sudo", needed to get permissions for install.' >&2
|
echo 'Could not find the command "sudo", needed to get permissions for install.' >&2
|
||||||
echo "If you are on Windows, please run your shell as an administrator, then" >&2
|
echo "If you are on Windows, please run your shell as an administrator, then" >&2
|
||||||
echo "rerun this script. Otherwise, please run this script as root, or install" >&2
|
echo "rerun this script. Otherwise, please run this script as root, or install" >&2
|
||||||
echo "sudo." >&2
|
echo "sudo." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if ! sudo -v; then
|
if ! sudo -v; then
|
||||||
|
|
@ -471,7 +467,6 @@ elevate_priv() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Test if a location is writeable by trying to write to it. Windows does not let
|
# Test if a location is writeable by trying to write to it. Windows does not let
|
||||||
# you test writeability other than by writing: https://stackoverflow.com/q/1999988
|
# you test writeability other than by writing: https://stackoverflow.com/q/1999988
|
||||||
test_writeable() {
|
test_writeable() {
|
||||||
|
|
@ -487,57 +482,25 @@ test_writeable() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# parse the arguments passed and set the environment variables accordingly
|
# parse the arguments passed and set the environment variables accordingly
|
||||||
parse_args() {
|
parse_args() {
|
||||||
# parse argv variables
|
# parse argv variables
|
||||||
while [ "$#" -gt 0 ]; do
|
while [ "$#" -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-b | --bin-dir)
|
-b | --bin-dir) BIN_DIR="$2" && shift 2 ;;
|
||||||
BIN_DIR="$2"
|
-m | --man-dir) MAN_DIR="$2" && shift 2 ;;
|
||||||
shift 2
|
-a | --arch) ARCH="$2" && shift 2 ;;
|
||||||
;;
|
-s | --sudo) SUDO="$2" && shift 2 ;;
|
||||||
-m | --man-dir)
|
-h | --help) usage && exit 0 ;;
|
||||||
MAN_DIR="$2"
|
-b=* | --bin-dir=*) BIN_DIR="${1#*=}" && shift 1 ;;
|
||||||
shift 2
|
-m=* | --man-dir=*) MAN_DIR="${1#*=}" && shift 1 ;;
|
||||||
;;
|
-a=* | --arch=*) ARCH="${1#*=}" && shift 1 ;;
|
||||||
-a | --arch)
|
-s=* | --sudo=*) SUDO="${1#*=}" && shift 1 ;;
|
||||||
ARCH="$2"
|
*) err "Unknown option: $1" ;;
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-s | --sudo)
|
|
||||||
SUDO="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
-h | --help)
|
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
|
|
||||||
-b=* | --bin-dir=*)
|
|
||||||
BIN_DIR="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-m=* | --man-dir=*)
|
|
||||||
MAN_DIR="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-a=* | --arch=*)
|
|
||||||
ARCH="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-s=* | --sudo=*)
|
|
||||||
SUDO="${1#*=}"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
err "Unknown option: $1"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# This is put in braces to ensure that the script does not run until it is
|
# This is put in braces to ensure that the script does not run until it is
|
||||||
# downloaded completely.
|
# downloaded completely.
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue