-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.sh
More file actions
executable file
·37 lines (33 loc) · 829 Bytes
/
Copy pathpatch.sh
File metadata and controls
executable file
·37 lines (33 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
patchfile="$HOME/$USER-$HOSTNAME-dotfiles.patch"
dotfiles=( $( cd dots && find -type f -not -path '*/.vim/*' | sed 's/^\.\///') )
show_diff() {
for dotfile in ${dotfiles[@]}; do
diff -Naur $PWD/dots/$dotfile $HOME/$dotfile
done
}
apply_patch() {
[[ -n "$1" && "$1" != '--dry-run' ]]\
&& echo "Unknown option: $1"\
&& exit 3
[[ ! -e "$patchfile" ]]\
&& echo "Patch does not exist: $patchfile"\
&& exit
patch --force --quiet -i "$patchfile" --directory="$HOME" $1
}
case $1 in
"apply")
apply_patch $2
;;
"create")
show_diff > "$patchfile"
echo "Created patch-file: $patchfile"
;;
"")
show_diff
;;
*)
echo "Usage: $0 [create|apply [--dry-run]]"
exit 1
;;
esac