dblume commited on 2023-12-01 10:30:07
Showing 1 changed files, with 24 additions and 24 deletions.
... | ... |
@@ -1,8 +1,8 @@ |
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") |
|
5 |
-declare -r backup_dir=$HOME/backup_of_dotfiles_$(date "+%Y-%m-%d_%H%M%S") |
|
4 |
+declare -r SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}") |
|
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" |
... | ... |
@@ -29,23 +29,23 @@ do |
29 | 29 |
esac |
30 | 30 |
done |
31 | 31 |
|
32 |
-if [ ! -d $backup_dir/.ssh ]; then |
|
33 |
- ((DRY_RUN==0)) && mkdir -p $backup_dir/.ssh |
|
32 |
+if [ ! -d "${backup_dir}"/.ssh ]; then |
|
33 |
+ ((DRY_RUN==0)) && mkdir -p "${backup_dir}"/.ssh |
|
34 | 34 |
fi |
35 | 35 |
|
36 | 36 |
# Move original dot files to backup |
37 | 37 |
for i in "${dotfiles[@]}" |
38 | 38 |
do |
39 |
- if [ -e $HOME/"$i" ]; then |
|
40 |
- if ! cmp --silent $HOME/"$i" "$i" ; then |
|
39 |
+ if [ -e "$HOME"/"$i" ]; then |
|
40 |
+ if ! cmp --silent "$HOME"/"$i" "$i" ; then |
|
41 | 41 |
echo "$i" will be changed as follows: |
42 |
- diff $HOME/"$i" "$i" || true |
|
42 |
+ diff "$HOME"/"$i" "$i" || true |
|
43 | 43 |
if [ $DRY_RUN -eq 0 ]; then |
44 |
- mv $HOME/"$i" $backup_dir/"$i" |
|
44 |
+ mv "$HOME"/"$i" "${backup_dir}"/"$i" |
|
45 | 45 |
# Consider using symbolic links instead |
46 | 46 |
# so pulling updates automatically apply |
47 |
- cp "$i" $HOME/"$i" |
|
48 |
- echo "# vimdiff \"$HOME/$i\" \"$backup_dir/$i\"" |
|
47 |
+ cp "$i" "$HOME"/"$i" |
|
48 |
+ echo "# vimdiff \"$HOME/$i\" \"${backup_dir}/$i\"" |
|
49 | 49 |
else |
50 | 50 |
# Provide a diff that can still be used |
51 | 51 |
echo "# vimdiff \"$i\" \"$HOME/$i\"" |
... | ... |
@@ -56,24 +56,24 @@ do |
56 | 56 |
fi |
57 | 57 |
else |
58 | 58 |
echo "$i" will be added to HOME. |
59 |
- ((DRY_RUN==0)) && mkdir -p $HOME/$(dirname "$i") && cp "$i" $HOME/"$i" |
|
59 |
+ ((DRY_RUN==0)) && mkdir -p "$HOME"/"$(dirname "$i")" && cp "$i" "$HOME"/"$i" |
|
60 | 60 |
fi |
61 | 61 |
done |
62 | 62 |
|
63 |
-if ! diff -qr $HOME/.vim .vim > /dev/null ; then |
|
63 |
+if ! diff -qr "$HOME"/.vim .vim > /dev/null ; then |
|
64 | 64 |
if [ $DRY_RUN -eq 0 ]; then |
65 |
- if [ -d $HOME/.vim ]; then |
|
66 |
- mv $HOME/.vim $backup_dir |
|
65 |
+ if [ -d "$HOME"/.vim ]; then |
|
66 |
+ mv "$HOME"/.vim "${backup_dir}" |
|
67 | 67 |
fi |
68 |
- cp -r .vim $HOME |
|
69 |
- if [ -d $backup_dir/.vim ]; then |
|
68 |
+ cp -r .vim "$HOME" |
|
69 |
+ if [ -d "${backup_dir}"/.vim ]; then |
|
70 | 70 |
# Copy back proprietary file types (ex. ftdetect/my.vim), if any. |
71 | 71 |
# Print only the files that got moved back into ~/.vim |
72 |
- cp -rnv $backup_dir/.vim $HOME | grep " -> " | cut -d " " -f3 | \ |
|
72 |
+ cp -rnv "${backup_dir}"/.vim "$HOME" | grep " -> " | cut -d " " -f3 | \ |
|
73 | 73 |
xargs -I{} sh -c "test -f {} && echo Restored {}" || true |
74 | 74 |
fi |
75 | 75 |
fi |
76 |
- if [[ -d $backup_dir/.vim ]]; then |
|
76 |
+ if [[ -d "${backup_dir}"/.vim ]]; then |
|
77 | 77 |
if ! diff -qr "$backup_dir/.vim" "$HOME/.vim" ; then |
78 | 78 |
echo "# diff -qr \"$backup_dir/.vim\" \"$HOME/.vim\"" |
79 | 79 |
echo |
... | ... |
@@ -81,30 +81,30 @@ if ! diff -qr $HOME/.vim .vim > /dev/null ; then |
81 | 81 |
echo No change to the .vim/ directories after restoring proprietary files. |
82 | 82 |
fi |
83 | 83 |
else |
84 |
- echo No $backup_dir/.vim/ from which to restore proprietary files \(yet\). |
|
84 |
+ echo No "${backup_dir}"/.vim/ from which to restore proprietary files \(yet\). |
|
85 | 85 |
fi |
86 | 86 |
else |
87 | 87 |
echo No change to the .vim/ directories. |
88 | 88 |
fi |
89 | 89 |
|
90 | 90 |
# Make a directory for vim undo |
91 |
-if [ ! -d $HOME/.vim_undo ]; then |
|
92 |
- ((DRY_RUN==0)) && mkdir -p $HOME/.vim_undo |
|
91 |
+if [ ! -d "$HOME"/.vim_undo ]; then |
|
92 |
+ ((DRY_RUN==0)) && mkdir -p "$HOME"/.vim_undo |
|
93 | 93 |
fi |
94 | 94 |
|
95 | 95 |
# I have device local secrets in .localrc and a github secret in .gitconfig.local |
96 | 96 |
for i in ".gitconfig.local" ".localrc" |
97 | 97 |
do |
98 |
- if [ ! -f $HOME/"$i" ]; then |
|
98 |
+ if [ ! -f "$HOME"/"$i" ]; then |
|
99 | 99 |
echo Consider copying $i from a similar acct. \(\'touch \"\$HOME/$i\"\' to hide this msg.\) |
100 | 100 |
fi |
101 | 101 |
done |
102 | 102 |
|
103 | 103 |
if [ $DRY_RUN -eq 0 ]; then |
104 |
- echo Your old dotfiles are backed up to $backup_dir |
|
104 |
+ echo Your old dotfiles are backed up to "${backup_dir}" |
|
105 | 105 |
echo Done. Check http://config.dlma.com for more. |
106 | 106 |
else |
107 |
- echo Your old dotfiles would have been backed up to $backup_dir |
|
107 |
+ echo Your old dotfiles would have been backed up to "${backup_dir}" |
|
108 | 108 |
echo Dry run completed. |
109 | 109 |
fi |
110 | 110 |
|
111 | 111 |