-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate
executable file
·124 lines (110 loc) · 2.75 KB
/
update
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
DOTFILES_DIR=$(dirname "$(readlink "$0" || echo "$0")")
DELETE=0
INSTALL=1
STOW_FOLDERS=()
function set_stow_folders() {
while [[ $# -gt 0 ]]; do
case $1 in
-D | --delete)
DELETE=1
INSTALL=0
shift
;;
-U | --update)
DELETE=1
INSTALL=1
shift
;;
-h | --help)
usage
exit 1
;;
-p | --private)
reset
private
shift
;;
-s | --shared)
reset
shared
shift
;;
-a | --all)
all
exit 1
;;
*)
STOW_FOLDERS+=("$1")
shift
;;
esac
done
if [[ ${#STOW_FOLDERS[@]} -eq 0 ]]; then
STOW_FOLDERS=($(/bin/ls -d -- */ | sed 's/\///g'))
fi
}
function all() {
ALL_FOLDERS="$(/bin/ls -d -- */ | tr '\n' ' ' | sed 's/\///g')"
echo "$ALL_FOLDERS"
}
function reset() {
STOW_FOLDERS=()
}
function shared() {
case ${OSTYPE} in
darwin*)
STOW_FOLDERS=(zsh tmux git tig nvim)
;;
linux-gnu*)
STOW_FOLDERS=(bash tmux git tig nvim)
;;
*)
reset
;;
esac
}
function private() {
case ${OSTYPE} in
darwin*)
STOW_FOLDERS=(zsh ripgrep tmux git-private tig nvim alacritty alacritty-macos iterm2 bat wakatime zathura w3m eza)
;;
linux-gnu*)
STOW_FOLDERS=(zsh ripgrep tmux git-private tig nvim alacritty alacritty-linux bat wakatime zathura w3m i3 wofi eza)
;;
*)
reset
;;
esac
}
function usage() {
cat << EOF
usage: $(basename "${0}") [--help] [--list] [--update | --delete]
[--private | --shared] [dirs]
options:
--help, -h print this
--delete, -D delete dotfiles
--private, -p select dotfiles for a private host
--shared, -s select dotfiles for a shared host
EOF
}
function update() {
for folder in "${STOW_FOLDERS[@]}"; do
if [[ ${DELETE} -eq 1 ]]; then
printf "Deleting %-17s" "$folder"
stow -t "$HOME" -D "$folder" 2> /dev/null
fi
if [[ ${INSTALL} -eq 1 ]]; then
printf "Installing %-17s" "$folder"
stow --ignore='\.DS_Store' -t "$HOME" "$folder"
fi
echo " ... Done"
done
}
function main() {
pushd "$DOTFILES_DIR" > /dev/null || exit
set_stow_folders "$@"
update
popd > /dev/null || exit
}
main "$@"