-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup
More file actions
executable file
·177 lines (145 loc) · 3.94 KB
/
Copy pathsetup
File metadata and controls
executable file
·177 lines (145 loc) · 3.94 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
#!/bin/bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
print_error() {
printf "\033[0;31m%s\033[0m\n" "$1"
}
print_log() {
local msg="$1 "
local status=" [$2]"
local columns
columns=$(tput cols 2>/dev/null || echo 80)
local adjust=$((columns - ${#msg} - ${#status}))
((adjust < 1)) && adjust=1
printf "%s" "$msg"
printf "%*s" "$adjust" "" | tr " " "."
printf "%s\n" "$status"
}
log_ok() {
print_log "$1" "OK"
}
log_skip() {
print_log "$1" "Skip"
}
install_xcode_command_line() {
if xcode-select -p >/dev/null 2>&1; then
log_skip "Xcode command line tools"
return
fi
xcode-select --install
print_error "Install Xcode command line tools, then run ./setup again."
exit 1
}
install_rosetta() {
if arch -arch x86_64 uname -m >/dev/null 2>&1; then
log_skip "Rosetta"
return
fi
softwareupdate --install-rosetta --agree-to-license
log_ok "Rosetta"
}
install_homebrew() {
if command -v brew >/dev/null 2>&1; then
log_skip "Homebrew"
return
fi
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
log_ok "Homebrew"
}
install_brew_bundle() {
brew bundle --file "${REPO_ROOT}/brew/Brewfile"
log_ok "Brew bundle"
}
ensure_directories() {
mkdir -p "$HOME/.config" "$HOME/.local/share/tmux/plugins" "$HOME/Projects/go"
log_ok "Directories"
}
backup_path() {
local target="$1"
if [ -L "$target" ] || [ -e "$target" ]; then
local backup="${target}.backup.$(date +%Y%m%d%H%M%S)"
mv "$target" "$backup"
log_ok "Backed up ${target}"
fi
}
link_path() {
local source="$1"
local target="$2"
mkdir -p "$(dirname "$target")"
if [ -L "$target" ] && [ "$(readlink "$target")" = "$source" ]; then
log_skip "Link ${target}"
return
fi
if [ -e "$target" ] || [ -L "$target" ]; then
backup_path "$target"
fi
ln -s "$source" "$target"
log_ok "Link ${target}"
}
clone_or_update() {
local repo="$1"
local target="$2"
if [ -d "$target/.git" ]; then
git -C "$target" pull --ff-only
log_ok "Update $(basename "$target")"
return
fi
rm -rf "$target"
git clone --depth 1 "$repo" "$target"
log_ok "Clone $(basename "$target")"
}
setup_macos() {
sh ./macos/.macos
log_ok "Set up macos settings"
}
link_configs() {
link_path "${REPO_ROOT}/.zshenv" "$HOME/.zshenv"
link_path "${REPO_ROOT}/.config/zsh" "$HOME/.config/zsh"
link_path "${REPO_ROOT}/.config/tmux" "$HOME/.config/tmux"
link_path "${REPO_ROOT}/.config/nvim" "$HOME/.config/nvim"
link_path "${REPO_ROOT}/.config/colima" "$HOME/.config/colima"
link_path "${REPO_ROOT}/.config/zed" "$HOME/.config/zed"
link_path "${REPO_ROOT}/.gitconfig" "$HOME/.gitconfig"
}
setup_tmux_plugins() {
clone_or_update "https://github.com/catppuccin/tmux.git" "$HOME/.local/share/tmux/plugins/catppuccin/tmux"
clone_or_update "https://github.com/tmux-plugins/tmux-battery.git" "$HOME/.local/share/tmux/plugins/tmux-plugins/tmux-battery"
clone_or_update "https://github.com/tmux-plugins/tmux-cpu.git" "$HOME/.local/share/tmux/plugins/tmux-plugins/tmux-cpu"
clone_or_update "https://github.com/tmux-plugins/tmux-resurrect.git" "$HOME/.local/share/tmux/plugins/tmux-plugins/tmux-resurrect"
}
setup_iterm() {
cp "${REPO_ROOT}/iterm/com.googlecode.iterm2.plist" "$HOME/Library/Preferences"
log_ok "iTerm preferences"
}
change_shell() {
if [ "${SHELL}" = "/bin/zsh" ]; then
log_skip "Default shell"
return
fi
chsh -s /bin/zsh "$(whoami)"
log_ok "Default shell"
}
main() {
if [ "$(uname)" != "Darwin" ]; then
print_error "This setup script currently supports macOS only."
exit 1
fi
sudo -v
while true; do
sudo -n true
sleep 60
kill -0 "$$" || exit
done 2>/dev/null &
install_xcode_command_line
install_rosetta
install_homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"
install_brew_bundle
ensure_directories
link_configs
setup_tmux_plugins
setup_iterm
setup_macos
change_shell
}
main "$@"