-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·125 lines (107 loc) · 2.91 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·125 lines (107 loc) · 2.91 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
#!/usr/bin/env bash
set -euo pipefail
dry_run=false
usage() {
printf 'Usage: %s [--dry-run|-n]\n' "${0##*/}"
}
while (($# > 0)); do
case "$1" in
--dry-run | -n)
dry_run=true
;;
--help | -h)
usage
exit 0
;;
*)
usage >&2
exit 1
;;
esac
shift
done
repo_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
common="$repo_root/hosts/common"
obook="$repo_root/hosts/obook"
obuntu="$repo_root/hosts/obuntu"
oarch="$repo_root/hosts/oarch"
conf="$HOME/.config"
host="$(hostname)"
run() {
if [[ "$dry_run" == true ]]; then
printf 'Would run:'
printf ' %q' "$@"
printf '\n'
else
"$@"
fi
}
link() {
local source="$1"
local target="$2"
[[ -e "$source" ]] || {
printf 'Missing source: %s\n' "$source" >&2
return 1
}
local target_dir
target_dir="$(dirname -- "$target")"
if [[ ! -d "$target_dir" ]]; then
run mkdir -p -- "$target_dir"
fi
if [[ -L "$target" ]]; then
run rm -- "$target"
elif [[ -e "$target" ]]; then
printf 'Refusing to replace non-symlink target: %s\n' "$target" >&2
return 1
fi
run ln -s -- "$source" "$target"
}
host_is() {
[[ "$host" == "$1" ]]
}
file_exists() {
[[ -e "$1" ]]
}
# Common
link "$common/config/ghostty" "$conf/ghostty"
link "$common/config/helix" "$conf/helix"
link "$common/config/starship.toml" "$conf/starship.toml"
link "$common/vimrc" "$HOME/.vimrc"
link "$common/config/atuin" "$conf/atuin"
link "$common/config/lazydocker" "$conf/lazydocker"
link "$common/config/lazygit" "$conf/lazygit"
link "$common/config/cheat" "$conf/cheat"
link "$common/config/tmux" "$conf/tmux"
link "$common/config/zsh" "$conf/zsh"
link "$common/config/zsh-patina" "$conf/zsh-patina"
link "$common/config/nvim" "$conf/nvim"
link "$common/config/lsd" "$conf/lsd"
# Shared between main computers
if host_is "obook.local" || host_is "oarch"; then
link "$common/config/git" "$conf/git"
link "$common/config/alacritty.toml" "$conf/alacritty.toml"
fi
# Mac (obook)
if host_is "obook.local"; then
link "$obook/config/fish" "$conf/fish"
link "$common/config/zed" "$conf/zed"
link "$obook/zshrc" "$HOME/.zshrc"
fi
# Arch (oarch)
if host_is "oarch"; then
link "$oarch/config/fish" "$conf/fish"
link "$oarch/config/bspwm" "$conf/bspwm"
link "$oarch/config/sxhkd" "$conf/sxhkd"
link "$oarch/config/dunst" "$conf/dunst"
link "$oarch/config/picom" "$conf/picom"
link "$oarch/config/rofi" "$conf/rofi"
link "$oarch/config/polybar" "$conf/polybar"
link "$oarch/config/betterlockscreenrc" "$conf/betterlockscreenrc"
link "$oarch/config/user-dirs.dirs" "$conf/user-dirs.dirs"
link "$oarch/config/user-dirs.locale" "$conf/user-dirs.locale"
link "$oarch/config/hypr" "$conf/hypr"
fi
# obuntu
if file_exists "$HOME/.obuntu"; then
link "$obuntu/zshrc" "$HOME/.zshrc"
fi