12
12
# which is admittedly extremely unlikely to the point of being impossible,
13
13
# this software will most likely follow suit.
14
14
15
+ # POSIX strict mode; set -eu would be the other way to write this
16
+ set -o errexit
17
+ set -o nounset
18
+ IFS=$( printf ' \n\t' )
19
+
15
20
# This should always be the first line of code to facilitate debugging
21
+ VCSH_DEBUG=' ' ; export VCSH_DEBUG
16
22
[ -n " $VCSH_DEBUG " ] && set -vx
17
23
18
24
@@ -36,6 +42,7 @@ fatal() {
36
42
# options that will modify our behaviour.
37
43
# Commands are handled at the end of this script.
38
44
# shellcheck disable=SC2220
45
+ VCSH_OPTION_CONFIG=' ' ; export VCSH_OPTION_CONFIG
39
46
while getopts c:dv flag; do
40
47
case " $flag " in
41
48
d)
@@ -593,7 +600,7 @@ if [ ! "x$VCSH_GITIGNORE" = 'xexact' ] && [ ! "x$VCSH_GITIGNORE" = 'xnone' ] &&
593
600
fatal " '\$ VCSH_GITIGNORE' must equal 'exact', 'none', or 'recursive'" 1
594
601
fi
595
602
596
- VCSH_COMMAND=$1 ; export VCSH_COMMAND
603
+ VCSH_COMMAND=${1-} ; export VCSH_COMMAND
597
604
598
605
case $VCSH_COMMAND in
599
606
clon|clo|cl) VCSH_COMMAND=clone;;
@@ -682,7 +689,7 @@ elif [ x"$VCSH_COMMAND" = x'status' ]; then
682
689
shift
683
690
fi
684
691
VCSH_REPO_NAME=$2 ; export VCSH_REPO_NAME
685
- elif [ -n " $2 " ]; then
692
+ elif [ -n " ${2-} " ]; then
686
693
VCSH_COMMAND=' run' ; export VCSH_COMMAND
687
694
VCSH_REPO_NAME=$1 ; export VCSH_REPO_NAME
688
695
GIT_DIR=$VCSH_REPO_D /$VCSH_REPO_NAME .git; export GIT_DIR
@@ -695,7 +702,8 @@ elif [ -n "$VCSH_COMMAND" ]; then
695
702
GIT_DIR=$VCSH_REPO_D /$VCSH_REPO_NAME .git; export GIT_DIR
696
703
[ -d " $GIT_DIR " ] || { help ; exit 1; }
697
704
else
698
- # $1 is empty
705
+ # $1 is empty. We exit 1 to discern from `vcsh help` and to help catch
706
+ # scripts which erroueously don't provide options
699
707
help && exit 1
700
708
fi
701
709
0 commit comments