shell script variables lowercase
dblume

dblume commited on 2023-12-03 23:17:36
Showing 1 changed files, with 10 additions and 10 deletions.

... ...
@@ -1,19 +1,19 @@
1 1
 #!/usr/bin/env bash
2 2
 set -eu -o pipefail # See: https://sipb.mit.edu/doc/safe-shell/
3 3
 
4
-declare -r SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
4
+declare -r script_name=$(basename "${BASH_SOURCE[0]}")
5 5
 declare -r backup_dir="$HOME"/backup_of_dotfiles_$(date "+%Y-%m-%d_%H%M%S")
6 6
 declare -a dotfiles=(".bashrc" ".bash_profile" ".vimrc" ".editrc" ".gitconfig"
7 7
                      ".gitignore" ".inputrc" ".tmux.conf" ".ssh/config" ".ripgreprc"
8 8
                      ".gdbinit" ".config/gitui/key_bindings.ron" ".visidatarc"
9 9
                      ".config/i3/config" ".config/i3status/config"
10 10
                      ".config/dunst/dunstrc")
11
-declare -i DRY_RUN=0
11
+declare -i dry_run=0
12 12
 
13 13
 ## exit the shell (with status 2) after printing the message
14 14
 usage() {
15 15
     echo "\
16
-$SCRIPT_NAME -hn
16
+$script_name -hn
17 17
     -h      Print this help text
18 18
     -n      Perform a dry run, to see what'll change
19 19
 "
... ...
@@ -25,13 +25,13 @@ while getopts "hn" OPTION
25 25
 do
26 26
   case $OPTION in
27 27
     h) usage;;
28
-    n) DRY_RUN=1;;
28
+    n) dry_run=1;;
29 29
     \?) usage;;
30 30
   esac
31 31
 done
32 32
 
33 33
 if [ ! -d "${backup_dir}"/.ssh ]; then
34
-    ((DRY_RUN==0)) && mkdir -p "${backup_dir}"/.ssh
34
+    ((dry_run==0)) && mkdir -p "${backup_dir}"/.ssh
35 35
 fi
36 36
 
37 37
 # Move original dot files to backup
... ...
@@ -41,7 +41,7 @@ do
41 41
         if ! cmp --silent "$HOME"/"$i" "$i" ; then
42 42
             echo "$i" will be changed as follows:
43 43
             diff "$HOME"/"$i" "$i" || true
44
-            if [ $DRY_RUN -eq 0 ]; then
44
+            if [ $dry_run -eq 0 ]; then
45 45
                 mv "$HOME"/"$i" "${backup_dir}"/"$i"
46 46
                 # Consider using symbolic links instead
47 47
                 # so pulling updates automatically apply
... ...
@@ -57,12 +57,12 @@ do
57 57
         fi
58 58
     else
59 59
         echo "$i" will be added to HOME.
60
-        ((DRY_RUN==0)) && mkdir -p "$HOME"/"$(dirname "$i")" && cp "$i" "$HOME"/"$i"
60
+        ((dry_run==0)) && mkdir -p "$HOME"/"$(dirname "$i")" && cp "$i" "$HOME"/"$i"
61 61
     fi
62 62
 done
63 63
 
64 64
 if ! diff -qr "$HOME"/.vim .vim > /dev/null ; then
65
-    if [ $DRY_RUN -eq 0 ]; then
65
+    if [ $dry_run -eq 0 ]; then
66 66
         if [ -d "$HOME"/.vim ]; then
67 67
             mv "$HOME"/.vim "${backup_dir}"
68 68
         fi
... ...
@@ -90,7 +90,7 @@ fi
90 90
 
91 91
 # Make a directory for vim undo
92 92
 if [ ! -d "$HOME"/.vim_undo ]; then
93
-    ((DRY_RUN==0)) && mkdir -p "$HOME"/.vim_undo
93
+    ((dry_run==0)) && mkdir -p "$HOME"/.vim_undo
94 94
 fi
95 95
 
96 96
 # I have device local secrets in .localrc and a github secret in .gitconfig.local
... ...
@@ -101,7 +101,7 @@ do
101 101
     fi
102 102
 done
103 103
 
104
-if [ $DRY_RUN -eq 0 ]; then
104
+if [ $dry_run -eq 0 ]; then
105 105
     echo Your old dotfiles are backed up to "${backup_dir}"
106 106
     echo Done. Check http://config.dlma.com for more.
107 107
 else
108 108