Skip to content

Commit 7c4e75f

Browse files
committed
[ cleanup ] follow the shellcheck advice
1 parent b7e5775 commit 7c4e75f

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

stdlib-install.sh

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,27 @@
66
set -eu
77

88
isDebugMode() {
9-
! [ -z ${DEBUG-} ]
9+
[ -n "${DEBUG-}" ]
1010
}
1111

12-
if ! [ -z ${SHELL_DEBUG-} ]; then
12+
if [ -n "${SHELL_DEBUG-}" ]; then
1313
set -x
1414
fi
1515

1616
throwError() {
17-
echo "\033[91m✗\033[0m $1." >&2
17+
printf "\033[91m✗\033[0m %s.\n" "$1" >&2
1818
exit 1
1919
}
2020

21-
logHappy() {
22-
echo "\033[32m✔\033[0m $1"
23-
}
24-
25-
logUnhappy() {
26-
echo "\033[91m✗\033[0m $1."
27-
}
28-
29-
logWarning() {
30-
echo "\033[93m⚠\033[0m $1"
31-
}
21+
logHappy() { printf "\033[32m✔\033[0m %s.\n" "$1"; }
22+
logUnhappy() { printf "\033[91m✗\033[0m %s.\n" "$1"; }
23+
logWarning() { printf "\033[93m⚠\033[0m %s.\n" "$1"; }
3224

3325
########################################################################
3426
## PRELIMINARY CHECKS
3527

3628
checkDependency () {
37-
if ! [ -x "$(command -v $1)" ]; then
29+
if ! [ -x "$(command -v "$1")" ]; then
3830
throwError "Missing dependency: I could not find the executable '$1'"
3931
elif isDebugMode; then
4032
logHappy "Found '$1'"
@@ -54,28 +46,29 @@ checkDependency "wget"
5446

5547
# Pick the Agda executable to analyse
5648
# unless the caller has specified one
57-
if [ -z ${AGDA_EXEC-} ]; then
49+
if [ -z "${AGDA_EXEC-}" ]; then
5850
while true; do
59-
read -p "What's the name of your Agda executable (default: agda)? " AGDA_EXEC
51+
printf "What's the name of your Agda executable (default: agda)? "
52+
read -r AGDA_EXEC
6053
if [ -z "$AGDA_EXEC" ]; then
6154
AGDA_EXEC=agda
6255
fi
6356
# Double check that the command exists
64-
if ! [ -x "$(command -v $AGDA_EXEC)" ]; then
57+
if ! [ -x "$(command -v "$AGDA_EXEC")" ]; then
6558
logUnhappy "'$AGDA_EXEC' is not a valid executable"
6659
else
6760
break
6861
fi
6962
done
70-
elif ! [ -x "$(command -v $AGDA_EXEC)" ]; then
63+
elif ! [ -x "$(command -v "$AGDA_EXEC")" ]; then
7164
throwError "'$AGDA_EXEC' is not a valid executable"
7265
fi
7366

7467
logHappy "Agda executable: $AGDA_EXEC"
7568

7669
# Ask the executable for its version number
7770
# unless the caller has specified one
78-
if [ -z ${AGDA_VERSION-} ]; then
71+
if [ -z "${AGDA_VERSION-}" ]; then
7972
# There is a more recent "--numeric-version" option but old
8073
# versions of Agda do not implement it!
8174
AGDA_VERSION=$($AGDA_EXEC --version | head -n 1 | sed "s/^[a-zA-Z ]*\(2[0-9.]*\)\(-.*\)*$/\1/")
@@ -90,27 +83,27 @@ logHappy "Agda version number: $AGDA_VERSION"
9083

9184
# Pick the install directory
9285
# unless the caller has specified one
93-
if [ -z ${AGDA_DIR-} ]; then
86+
if [ -z "${AGDA_DIR-}" ]; then
9487
AGDA_DIR=$($AGDA_EXEC --print-agda-app-dir | head -n 1 || true)
9588
if echo "$AGDA_DIR" | grep -Eq "^Error.*$"; then
9689
AGDA_DIR="$HOME/.agda"
9790
fi
98-
read -p "Where do you want to install the library (default: $AGDA_DIR)? " AGDA_DIR_OVERWRITE
99-
if ! [ -z "$AGDA_DIR_OVERWRITE" ]; then
91+
printf "Where do you want to install the library (default: %s)? " "$AGDA_DIR"
92+
read -r AGDA_DIR_OVERWRITE
93+
if [ -n "$AGDA_DIR_OVERWRITE" ]; then
10094
AGDA_DIR="$AGDA_DIR_OVERWRITE"
10195
fi
10296
fi
10397

10498
logHappy "Agda directory: $AGDA_DIR"
10599

106-
if [ -z ${STDLIB_VERSION-} ]; then
100+
if [ -z "${STDLIB_VERSION-}" ]; then
107101
case "$AGDA_VERSION" in
108102
"2.8.0") STDLIB_VERSION="2.3" ;;
109103
"2.7.0.1") STDLIB_VERSION="2.3" ;;
110104
"2.7.0") STDLIB_VERSION="2.2" ;;
111105
"2.6.4.3") STDLIB_VERSION="2.1" ;;
112106
"2.6.4.2") STDLIB_VERSION="2.0" ;;
113-
"2.6.4.2") STDLIB_VERSION="2.0" ;;
114107
"2.6.4.1") STDLIB_VERSION="2.0" ;;
115108
"2.6.4") STDLIB_VERSION="2.0" ;;
116109
"2.6.3") STDLIB_VERSION="1.7.3" ;;
@@ -145,7 +138,8 @@ logHappy "Successfully downloaded the standard library"
145138
if [ -d "$STDLIB_DIR_NAME" ]; then
146139
logWarning "The directory $AGDA_DIR/$STDLIB_DIR_NAME already exists."
147140
while true; do
148-
read -p "Do you want to overwrite it? (yN) " DIR_OVERWRITE
141+
printf "Do you want to overwrite it? (yN) "
142+
read -r DIR_OVERWRITE
149143
DIR_OVERWRITE=${DIR_OVERWRITE:-n}
150144
case "$DIR_OVERWRITE" in
151145
[yY]*) DIR_OVERWRITE="y"; break;;

0 commit comments

Comments
 (0)