Repository navigation
Expand file tree
/
Copy pathreset.sh
More file actions
executable file
·288 lines (254 loc) · 7.08 KB
/
Copy pathreset.sh
File metadata and controls
executable file
·288 lines (254 loc) · 7.08 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env bash
set -Eeuo pipefail
readonly REPO_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
DRY_RUN=0
BACKUP_ROOT=""
targets=()
usage() {
cat <<'EOF'
Usage: ./reset.sh [options] [target ...]
Install the core terminal configuration. With no targets, this installs:
top, zsh, nvim, and tmux, plus detected Rime and kitty configurations.
Targets:
core Install top, zsh, nvim, and tmux
all Install core plus Rime/kitty when detected (default)
top Install ~/.toprc
zsh Install ~/.zshrc
nvim Install Neovim's init.lua and ~/.init.lua compatibility link
tmux Install ~/.tmux.conf and ~/.tmux.conf.local
kitty Install ~/.config/kitty/kitty.conf
vim Install ~/.vimrc
mycli Install ~/.myclirc
imv Install ~/.config/imv/config
x11 Install ~/.Xresources and ~/.xprofile
dwm Install the common X11 files and the dwm ~/.xinitrc
i3 Install the common X11 files and the i3 ~/.xinitrc
river Install ~/.config/river/init
rime Merge Rime files into Squirrel (macOS) or fcitx5 (Linux)
Options:
-n, --dry-run Print changes without writing anything
--backup-dir DIR Store replaced files under DIR
-h, --help Show this help
System package setup remains available separately through ubuntu.sh.
EOF
}
while (($#)); do
case "$1" in
-n|--dry-run)
DRY_RUN=1
;;
--backup-dir)
(($# >= 2)) || {
printf 'error: --backup-dir requires a directory\n' >&2
exit 2
}
BACKUP_ROOT="$2"
shift
;;
-h|--help)
usage
exit 0
;;
--)
shift
targets+=("$@")
break
;;
-*)
printf 'error: unknown option: %s\n' "$1" >&2
usage >&2
exit 2
;;
*)
targets+=("$1")
;;
esac
shift
done
if ((${#targets[@]} == 0)); then
targets=(all)
fi
has_dwm=0
has_i3=0
for target in "${targets[@]}"; do
case "$target" in
core|all|top|zsh|nvim|tmux|kitty|vim|mycli|imv|x11|river|rime)
;;
dwm)
has_dwm=1
;;
i3)
has_i3=1
;;
*)
printf 'error: unknown target: %s\n' "$target" >&2
usage >&2
exit 2
;;
esac
done
if [[ "$has_dwm" == "1" && "$has_i3" == "1" ]]; then
printf 'error: dwm and i3 both install ~/.xinitrc; choose one\n' >&2
exit 2
fi
export DRY_RUN
if [[ -n "$BACKUP_ROOT" ]]; then
export BACKUP_ROOT
fi
# shellcheck source=scripts/lib/install.sh
source "$REPO_ROOT/scripts/lib/install.sh"
install_top() {
install_file "$REPO_ROOT/config/top/toprc" "$HOME/.toprc"
}
install_zsh() {
install_file "$REPO_ROOT/config/zsh/zshrc" "$HOME/.zshrc"
}
install_nvim() {
local init_path="$HOME/.config/nvim/init.lua"
install_file "$REPO_ROOT/config/nvim/init.lua" "$init_path"
install_symlink "$init_path" "$HOME/.init.lua"
}
install_tmux() {
install_file "$REPO_ROOT/config/tmux/tmux.conf" "$HOME/.tmux.conf"
install_file "$REPO_ROOT/config/tmux/tmux.conf.local" "$HOME/.tmux.conf.local"
}
install_kitty() {
install_file "$REPO_ROOT/config/kitty/kitty.conf" "$HOME/.config/kitty/kitty.conf"
}
install_vim() {
install_file "$REPO_ROOT/config/vim/vimrc" "$HOME/.vimrc"
}
install_mycli() {
install_file "$REPO_ROOT/config/mycli/myclirc" "$HOME/.myclirc"
}
install_imv() {
install_file "$REPO_ROOT/config/imv/config" "$HOME/.config/imv/config"
}
install_x11() {
install_file "$REPO_ROOT/config/x11/Xresources" "$HOME/.Xresources"
install_file "$REPO_ROOT/config/x11/xprofile" "$HOME/.xprofile"
}
install_dwm() {
install_x11
install_file "$REPO_ROOT/config/x11/dwm.xinitrc" "$HOME/.xinitrc" 0755
}
install_i3() {
install_x11
install_file "$REPO_ROOT/config/x11/i3.xinitrc" "$HOME/.xinitrc" 0755
}
install_river() {
install_file "$REPO_ROOT/config/river/init" "$HOME/.config/river/init" 0755
}
install_rime() {
local rime_home
local platform
platform="$(uname -s)"
case "$platform" in
Darwin) rime_home="$HOME/Library/Rime" ;;
Linux) rime_home="$HOME/.local/share/fcitx5/rime" ;;
*) die "unsupported Rime platform: $platform" ;;
esac
install_tree_merge "$REPO_ROOT/config/rime" "$rime_home"
if [[ "$platform" == Darwin ]]; then
log "select Squirrel's Deploy menu item to rebuild Rime data"
elif [[ -f "$rime_home/Makefile" ]]; then
log "rebuild Rime data"
run make -C "$rime_home"
else
log "no Makefile in $rime_home; skipping rebuild"
fi
}
# Explicit targets can prepare configuration before the application is installed.
# Automatic installation requires a supported OS and application/config evidence.
install_detected() {
local platform
platform="$(uname -s)"
case "$platform" in
Darwin|Linux) ;;
*)
log "skip Rime and kitty: unsupported platform $platform"
return 0
;;
esac
if command -v kitty >/dev/null 2>&1 || [[ -d "$HOME/.config/kitty" ]] ||
{ [[ "$platform" == Darwin ]] &&
[[ -d /Applications/kitty.app || -d "$HOME/Applications/kitty.app" ]]; }; then
install_kitty
else
log "skip kitty: no kitty executable, app, or configuration directory detected"
fi
if [[ "$platform" == Darwin ]]; then
if [[ -d /Library/Input\ Methods/Squirrel.app ||
-d "$HOME/Library/Input Methods/Squirrel.app" ||
-d "$HOME/Library/Rime" ]]; then
install_rime
else
log "skip Rime: no Squirrel app or ~/Library/Rime directory detected"
fi
elif [[ -d "$HOME/.local/share/fcitx5/rime" ]] ||
command -v fcitx5-rime_deployer >/dev/null 2>&1; then
install_rime
else
log "skip Rime: no fcitx5-rime_deployer or fcitx5 Rime directory detected"
fi
}
install_target() {
case "$1" in
top)
install_top
;;
zsh)
install_zsh
;;
nvim)
install_nvim
;;
tmux)
install_tmux
;;
kitty)
install_kitty
;;
vim)
install_vim
;;
mycli)
install_mycli
;;
imv)
install_imv
;;
x11)
install_x11
;;
dwm)
install_dwm
;;
i3)
install_i3
;;
river)
install_river
;;
rime)
install_rime
;;
all)
install_target core
install_detected
;;
core)
install_top
install_zsh
install_nvim
install_tmux
;;
*)
die "unknown target: $1"
;;
esac
}
for target in "${targets[@]}"; do
install_target "$target"
done
print_backup_summary