1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-05 12:57:50 +00:00

style: address shellcheck issues in install.sh (#1305)

Fixes some shellcheck issues in the install script. Also normalizes
formatting with `shfmt` program.
This commit is contained in:
Dario Vladović 2020-06-10 20:40:05 +02:00 committed by GitHub
parent 525dfef9a7
commit 30ff5913be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,19 +34,19 @@ MAGENTA="$(tput setaf 5 2>/dev/null || echo '')"
NO_COLOR="$(tput sgr0 2>/dev/null || echo '')" NO_COLOR="$(tput sgr0 2>/dev/null || echo '')"
info() { info() {
printf "${BOLD}${GREY}>${NO_COLOR} $@\n" printf "%s\n" "${BOLD}${GREY}>${NO_COLOR} $*"
} }
warn() { warn() {
printf "${YELLOW}! $@${NO_COLOR}\n" printf "%s\n" "${YELLOW}! $*${NO_COLOR}"
} }
error() { error() {
printf "${RED}x $@${NO_COLOR}\n" >&2 printf "%s\n" "${RED}x $*${NO_COLOR}" >&2
} }
complete() { complete() {
printf "${GREEN}${NO_COLOR} $@\n" printf "%s\n" "${GREEN}${NO_COLOR} $*"
} }
# Gets path to a temporary file, even if # Gets path to a temporary file, even if
@ -54,7 +54,7 @@ get_tmpfile(){
local suffix local suffix
suffix="$1" suffix="$1"
if hash mktemp; then if hash mktemp; then
printf "$(mktemp).${suffix}" printf "%s.%s" "$(mktemp)" "${suffix}"
else else
# No really good options here--let's pick a default + hope # No really good options here--let's pick a default + hope
printf "/tmp/starship.%s" "${suffix}" printf "/tmp/starship.%s" "${suffix}"
@ -114,7 +114,7 @@ fetch_and_unpack(){
# I'd like to separate this into a fetch() and unpack() function, but I can't # I'd like to separate this into a fetch() and unpack() function, but I can't
# figure out how to get bash functions to read STDIN/STDOUT from pipes # figure out how to get bash functions to read STDIN/STDOUT from pipes
if [ "${EXT}" = "tar.gz" ]; then if [ "${EXT}" = "tar.gz" ]; then
fetch "${URL}" | ${sudo} tar xzf${VERBOSE} - -C "${BIN_DIR}" fetch "${URL}" | ${sudo} tar xzf "${VERBOSE}" - -C "${BIN_DIR}"
elif [ "${EXT}" = "zip" ]; then elif [ "${EXT}" = "zip" ]; then
# According to https://unix.stackexchange.com/q/2690, zip files cannot be read # According to https://unix.stackexchange.com/q/2690, zip files cannot be read
# through a pipe. We'll have to do our own file-based setup. # through a pipe. We'll have to do our own file-based setup.
@ -132,7 +132,7 @@ fetch_and_unpack(){
elevate_priv() { elevate_priv() {
if ! hash sudo 2>/dev/null; then if ! hash sudo 2>/dev/null; then
error "Could not find the command \"sudo\", needed to get permissions for install." error 'Could not find the command "sudo", needed to get permissions for install.'
info "If you are on Windows, please run your shell as an administrator, then" info "If you are on Windows, please run your shell as an administrator, then"
info "rerun this script. Otherwise, please run this script as root, or install" info "rerun this script. Otherwise, please run this script as root, or install"
info "sudo." info "sudo."
@ -210,17 +210,17 @@ detect_arch() {
confirm() { confirm() {
if [ -z "${FORCE-}" ]; then if [ -z "${FORCE-}" ]; then
printf "${MAGENTA}?${NO_COLOR} $@ ${BOLD}[y/N]${NO_COLOR} " printf "%s " "${MAGENTA}?${NO_COLOR} $* ${BOLD}[y/N]${NO_COLOR}"
set +e set +e
read -r yn </dev/tty read -r yn </dev/tty
rc=$? rc=$?
set -e set -e
if [ $rc -ne 0 ]; then if [ $rc -ne 0 ]; then
error "Error reading from prompt (please re-run with the \`--yes\` option)" error 'Error reading from prompt (please re-run with the `--yes` option)'
exit 1 exit 1
fi fi
if [ "$yn" != "y" ] && [ "$yn" != "yes" ]; then if [ "$yn" != "y" ] && [ "$yn" != "yes" ]; then
error "Aborting (please answer \"yes\" to continue)" error 'Aborting (please answer "yes" to continue)'
exit 1 exit 1
fi fi
fi fi
@ -237,7 +237,8 @@ check_bin_dir() {
# https://stackoverflow.com/a/11655875 # https://stackoverflow.com/a/11655875
local good local good
good=$( IFS=: good=$(
IFS=:
for path in $PATH; do for path in $PATH; do
if [ "${path}" = "${bin_dir}" ]; then if [ "${path}" = "${bin_dir}" ]; then
echo 1 echo 1
@ -271,22 +272,61 @@ fi
# parse argv variables # parse argv variables
while [ "$#" -gt 0 ]; do while [ "$#" -gt 0 ]; do
case "$1" in case "$1" in
-p|--platform) PLATFORM="$2"; shift 2;; -p | --platform)
-b|--bin-dir) BIN_DIR="$2"; shift 2;; PLATFORM="$2"
-a|--arch) ARCH="$2"; shift 2;; shift 2
-B|--base-url) BASE_URL="$2"; shift 2;; ;;
-b | --bin-dir)
BIN_DIR="$2"
shift 2
;;
-a | --arch)
ARCH="$2"
shift 2
;;
-B | --base-url)
BASE_URL="$2"
shift 2
;;
-V|--verbose) VERBOSE=1; shift 1;; -V | --verbose)
-f|-y|--force|--yes) FORCE=1; shift 1;; VERBOSE=1
shift 1
;;
-f | -y | --force | --yes)
FORCE=1
shift 1
;;
-p=*|--platform=*) PLATFORM="${1#*=}"; shift 1;; -p=* | --platform=*)
-b=*|--bin-dir=*) BIN_DIR="${1#*=}"; shift 1;; PLATFORM="${1#*=}"
-a=*|--arch=*) ARCH="${1#*=}"; shift 1;; shift 1
-B=*|--base-url=*) BASE_URL="${1#*=}"; shift 1;; ;;
-V=*|--verbose=*) VERBOSE="${1#*=}"; shift 1;; -b=* | --bin-dir=*)
-f=*|-y=*|--force=*|--yes=*) FORCE="${1#*=}"; shift 1;; BIN_DIR="${1#*=}"
shift 1
;;
-a=* | --arch=*)
ARCH="${1#*=}"
shift 1
;;
-B=* | --base-url=*)
BASE_URL="${1#*=}"
shift 1
;;
-V=* | --verbose=*)
VERBOSE="${1#*=}"
shift 1
;;
-f=* | -y=* | --force=* | --yes=*)
FORCE="${1#*=}"
shift 1
;;
*) error "Unknown option: $1"; exit 1;; *)
error "Unknown option: $1"
exit 1
;;
esac esac
done done
@ -298,7 +338,7 @@ if [ "${ARCH}" = "i386" ]; then
exit 1 exit 1
fi fi
printf " ${UNDERLINE}Configuration${NO_COLOR}\n" printf " %s\n" "${UNDERLINE}Configuration${NO_COLOR}"
info "${BOLD}Bin directory${NO_COLOR}: ${GREEN}${BIN_DIR}${NO_COLOR}" info "${BOLD}Bin directory${NO_COLOR}: ${GREEN}${BIN_DIR}${NO_COLOR}"
info "${BOLD}Platform${NO_COLOR}: ${GREEN}${PLATFORM}${NO_COLOR}" info "${BOLD}Platform${NO_COLOR}: ${GREEN}${PLATFORM}${NO_COLOR}"
info "${BOLD}Arch${NO_COLOR}: ${GREEN}${ARCH}${NO_COLOR}" info "${BOLD}Arch${NO_COLOR}: ${GREEN}${ARCH}${NO_COLOR}"