dblume commited on 2024-03-12 17:24:55
Showing 1 changed files, with 25 additions and 30 deletions.
Now that I want to update three directories, it makes sense to do that in a function. 1. .vim/ 2. .config/nvim/ 3. .local/share/nvim/site/plugin/
... | ... |
@@ -7,8 +7,7 @@ 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 |
- ".config/dunst/dunstrc" ".config/nvim/init.vim" |
|
11 |
- ".config/nvim/colors/nvim_desert.vim") |
|
10 |
+ ".config/dunst/dunstrc") |
|
12 | 11 |
declare -i dry_run=0 |
13 | 12 |
|
14 | 13 |
## exit the shell (with status 2) after printing the message |
... | ... |
@@ -62,49 +61,45 @@ do |
62 | 61 |
fi |
63 | 62 |
done |
64 | 63 |
|
65 |
-if ! diff -qr "$HOME"/.vim .vim > /dev/null ; then |
|
64 |
+update_dir () { |
|
65 |
+ if ! diff -qr "$HOME"/"$1" "$1" > /dev/null ; then |
|
66 |
+ local parentdir="$(dirname "$1")" |
|
67 |
+ |
|
66 | 68 |
if [ $dry_run -eq 0 ]; then |
67 |
- if [ -d "$HOME"/.vim ]; then |
|
68 |
- mv "$HOME"/.vim "${backup_dir}" |
|
69 |
+ if [ -d "$HOME"/"$1" ]; then |
|
70 |
+ mkdir -p "${backup_dir}"/"$parentdir" |
|
71 |
+ mv "$HOME"/"$1" "${backup_dir}"/"$parentdir" |
|
72 |
+ else |
|
73 |
+ mkdir -p "$HOME"/"$parentdir" |
|
69 | 74 |
fi |
70 |
- cp -r .vim "$HOME" |
|
71 |
- if [ -d "${backup_dir}"/.vim ]; then |
|
75 |
+ cp -RL "$1" "$HOME"/"$parentdir" |
|
76 |
+ if [ -d "${backup_dir}"/"$1" ]; then |
|
72 | 77 |
# Copy back proprietary file types (ex. ftdetect/my.vim), if any. |
73 |
- # Print only the files that got moved back into ~/.vim |
|
74 |
- cp -rnv "${backup_dir}"/.vim "$HOME" | grep " -> " | cut -d " " -f3 | \ |
|
78 |
+ # Print only the files that got moved back into ~/"$1" |
|
79 |
+ cp -RLnv "${backup_dir}"/"$1" "$HOME"/"$parentdir" | grep " -> " | cut -d " " -f3 | \ |
|
75 | 80 |
xargs -I{} sh -c "test -f {} && echo Restored {}" || true |
76 | 81 |
fi |
77 | 82 |
fi |
78 |
- if [[ -d "${backup_dir}"/.vim ]]; then |
|
79 |
- if ! diff -qr "$backup_dir/.vim" "$HOME/.vim" ; then |
|
80 |
- echo "# diff -qr \"$backup_dir/.vim\" \"$HOME/.vim\"" |
|
83 |
+ if [[ -d "${backup_dir}"/"$1" ]]; then |
|
84 |
+ if ! diff -qr "$backup_dir"/"$1" "$HOME"/"$1" ; then |
|
85 |
+ echo "# diff -qr \"$backup_dir/$1\" \"$HOME/$1\"" |
|
81 | 86 |
echo |
82 | 87 |
else |
83 |
- echo No change to the .vim/ directories after restoring proprietary files. |
|
88 |
+ echo No change to the "$1"/ directories after restoring proprietary files. |
|
84 | 89 |
fi |
85 | 90 |
else |
86 |
- echo No "${backup_dir}"/.vim/ from which to restore proprietary files \(yet\). |
|
91 |
+ echo No "${backup_dir}"/"$1"/ from which to restore proprietary files \(yet\). |
|
87 | 92 |
fi |
88 | 93 |
else |
89 |
- echo No change to the .vim/ directories. |
|
94 |
+ echo No change to the "$1"/ directories. |
|
90 | 95 |
fi |
96 |
+} |
|
91 | 97 |
|
92 |
-# TODO: Neovim's plugins go in ~/.local/share/nvim/site/plugin/ |
|
98 |
+update_dir ".vim" |
|
99 |
+update_dir ".config/nvim" |
|
100 |
+# Neovim's plugins go in ~/.local/share/nvim/site/plugin/ |
|
93 | 101 |
# https://neovim.io/doc/user/usr_05.html |
94 |
-if ! diff -qr "$HOME"/.local/share/nvim/site/plugin .local/share/nvim/site/plugin > /dev/null ; then |
|
95 |
- if [ $dry_run -eq 0 ]; then |
|
96 |
- if [ -d "$HOME"/.local/share/nvim/site/plugin/ ]; then |
|
97 |
- mkdir -p "${backup_dir}"/.local/share/nvim/site/plugin |
|
98 |
- mv "$HOME"/.local/share/nvim/site/plugin/* "${backup_dir}"/.local/share/nvim/site/plugin/ |
|
99 |
- else |
|
100 |
- mkdir -p "$HOME"/.local/share/nvim/site/plugin |
|
101 |
- fi |
|
102 |
- cp -r .local/share/nvim/site/plugin/* "$HOME"/.local/share/nvim/site/plugin/ |
|
103 |
- fi |
|
104 |
- echo Check the plugins in .local/share/nvim/site/plugin/ |
|
105 |
-else |
|
106 |
- echo No change to the .local/share/nvim/site/plugin/ directories. |
|
107 |
-fi |
|
102 |
+update_dir ".local/share/nvim/site/plugin" |
|
108 | 103 |
|
109 | 104 |
# Make a directory for vim undo |
110 | 105 |
if [ ! -d "$HOME"/.vim_undo ]; then |
111 | 106 |