-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
executable file
·77 lines (63 loc) · 2.06 KB
/
backup.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env zsh
#
# Helper script to conveniently create a backup and/or apply it.
# Use with caution, I'm not very good with shell scripts.
# Requires ZSH to run (because I used ZSH-specific features, duh).
#
PROFILE="$HOME/.profile"
# Tell this script where your dotfiles you wish to backup are located.
# Personally, I only care about those in my .config folder, and thus this script
# is kinda written with that in mind.
PREFIX="$HOME/.config/"
# Files to backup. If it's entire directories, postpend them with a slash.
# For individual files, don't do that.
#
# Order matters here: List directories first, then specific files, especially
# when you have individual files in directories you want to copy.
FILES=( "bat/" "dunst/" "fontconfig/" "i3/" "i3status-rust/" "kitty/"
"tmux/" "rofi/" "picom.conf" "zsh/custom" "zsh/.zshrc" "zsh/.zlogin" "pythonrc.py" )
# We remove the currently present parent folders to avoid copying our (new)
# backups into these parent folders, thus keeping the structure tight and
# actually usable.
clean() {
for conf in "${FILES[@]}"; do
parent=${conf%%/*}
rm -rf $parent
done
}
make_backup() {
clean
echo "\033[32;1m==>\033[0m \033[1mCopying $PROFILE...\033[0m"
cp $PROFILE profile
for conf in "${FILES[@]}"; do
parent=${conf%%/*}
echo "\033[32;1m==>\033[0m \033[1mCopying $PREFIX$conf into $parent...\033[0m"
cp -r $PREFIX$conf $parent
done
# Remove this directory because it contains (generally speaking) git
# repositories, we don't want that submodule jank(tm). If you have your own
# plugins written and don't track them with git feel free to modify this line.
rm -rf zsh/plugins
rm -rf tmux/plugins
}
show_help() {
echo "Usage:
backup [action]
Create and/or apply a backup of dotfiles.
Configure the paths and whatnot by editing the script.
Actions:
create: create a backup and store it in this folder.
-h | --help: Show this message. This is the default."
exit 0
}
case "$1" in
-h | --help )
show_help
;;
create )
make_backup
;;
* )
show_help
;;
esac