Skip to content

Commit a84a3af

Browse files
authored
feat(install): Add posix shell check (starship#3474)
* feat(install): Add posix shell check * Change function name
1 parent 4f46411 commit a84a3af

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

install/install.sh

+18-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ has() {
4040
command -v "$1" 1>/dev/null 2>&1
4141
}
4242

43+
# Make sure user is not using zsh or non-POSIX-mode bash, which can cause issues
44+
verify_shell_is_posix_or_exit() {
45+
if [ -n "${ZSH_VERSION+x}" ]; then
46+
error "Running installation script with \`zsh\` is known to cause errors."
47+
error "Please use \`sh\` instead."
48+
exit 1
49+
elif [ -n "${BASH_VERSION+x}" ] && [ -z "${POSIXLY_CORRECT+x}" ]; then
50+
error "Running installation script with non-POSIX \`bash\` may cause errors."
51+
error "Please use \`sh\` instead."
52+
exit 1
53+
else
54+
true # No-op: no issues detected
55+
fi
56+
}
57+
4358
# Gets path to a temporary file, even if
4459
get_tmpfile() {
4560
suffix="$1"
@@ -355,7 +370,6 @@ print_install() {
355370
printf "\n"
356371
}
357372

358-
359373
is_build_available() {
360374
arch="$1"
361375
platform="$2"
@@ -399,6 +413,9 @@ if [ -z "${BASE_URL-}" ]; then
399413
BASE_URL="https://github.com/starship/starship/releases"
400414
fi
401415

416+
# Non-POSIX shells can break once executing code due to semantic differences
417+
verify_shell_is_posix_or_exit
418+
402419
# parse argv variables
403420
while [ "$#" -gt 0 ]; do
404421
case "$1" in

0 commit comments

Comments
 (0)