-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·240 lines (211 loc) · 8.64 KB
/
setup.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
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
#!/usr/bin/env bash
CONFIG_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RED=$'\033[0;31m'
GREEN=$'\033[0;32m'
YELLOW=$'\033[0;33m'
PURPLE=$'\033[0;35m'
RESET=$'\033[0m'
printf "Beginning configuration setup\n"
printf -- "- Using %s%s%s as source of config truth\n" "${PURPLE}" "${CONFIG_HOME}" "${RESET}"
if [[ "$RECLONE" == "1" ]]; then
printf -- "- %sWill overwrite existing repos when needed%s\n" "${RED}" "${RESET}"
else
printf -- "- %sWill pull latest versions of relevant git repos%s\n" "${WHITE}" "${RESET}"
fi
printf "\n"
# helpers
function overwrite_with_symlink {
# set -x
if [[ -L "$2" && "$(readlink "$2")" = "$1" ]]; then
# symlink to expected file already exists, no action needed
printf "│ %s%s %s %s\n" "${GREEN}" "${RESET}" "$2" "$1"
return
elif [[ -d "$2" ]]; then
rm -rf "$2"
fi
ln -Fs "$1" "$2"
printf "│ %s%s %s %s\n" "${GREEN}" "${RESET}" "$2" "$1"
}
function clone_repo {
repo="$1"
git_repo_folder="${HOME}/code/$(echo "$repo" | rev | cut -d/ -f1 | rev | cut -d. -f1)"
if [[ "${RECLONE}" == "true" || ! -d "${git_repo_folder}" ]]; then
rm -rf "${git_repo_folder}"
GIT_TERMINAL_PROMPT=0 git clone --single-branch --recursive "${repo}" "${git_repo_folder}"
printf "│ %s%s %s %s\n" "${GREEN}" "${RESET}" "${repo}" "${git_repo_folder}"
elif [[ -z "${DONT_PULL}" ]]; then
GIT_TERMINAL_PROMPT=0 git -C "$git_repo_folder" pull
GIT_TERMINAL_PROMPT=0 git -C "$git_repo_folder" submodule update --init --recursive
printf "│ %s%s Pulled latest %s %s\n" "${GREEN}" "${RESET}" "${repo}" "${git_repo_folder}"
else
printf "│ %s%s %s %s\n" "${GREEN}" "${RESET}" "${repo}" "${git_repo_folder}"
fi
}
# individual setup steps
function setup_init {
printf "%s... init ...%s\n" "${YELLOW}" "${RESET}"
mkdir -p "${HOME}/.config/"
printf "│ %s%s ~/.config present\n" "${GREEN}" "${RESET}"
}
function setup_brew {
printf "%s Brew, bundles%s\n" "${YELLOW}" "${RESET}"
if command -v brew &>/dev/null; then
printf "│ %s%s Homebrew already installed\n" "${GREEN}" "${RESET}"
else
printf "│ %s %s Installing Homebrew\n" "${YELLOW}" "${RESET}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew update
brew bundle --file="${CONFIG_HOME}/Brewfile"
printf "│ %s%s Finished install from Brewfile\n" "${GREEN}" "${RESET}"
brew doctor
}
function setup_shell {
printf "%s zsh, tmux, Alacritty%s\n" "${YELLOW}" "${RESET}"
# common shell configs
overwrite_with_symlink "${CONFIG_HOME}/_aliases" "${HOME}/.aliases"
touch "${CONFIG_HOME}/_zshlocal"
printf "│ %s%s %s/_zshlocal ready\n" "${GREEN}" "${RESET}" "${CONFIG_HOME}"
overwrite_with_symlink "${CONFIG_HOME}/_zshlocal" "${HOME}/.zshlocal"
# LSCOLORS via vivid + trapd00r
overwrite_with_symlink "${CONFIG_HOME}/_lscolors" "${HOME}/.lscolors"
# TODO: use vivid instead https://github.com/trapd00r/LS_COLORS/issues/195
# mkdir -p "${HOME}/.config/vivid/themes"
# overwrite_with_symlink "${CONFIG_HOME}/vivid_trapd00r.yml" "${HOME}/.config/vivid/themes/trapd00r.yml"
# shell tools
clone_repo "https://github.com/purajit/venv_manager.git"
overwrite_with_symlink "${CONFIG_HOME}/atuin-config.toml" "${HOME}/.config/atuin/config.toml"
# zsh
overwrite_with_symlink "${CONFIG_HOME}/_zshrc" "${HOME}/.zshrc"
overwrite_with_symlink "${CONFIG_HOME}/_zprofile" "${HOME}/.zprofile"
# tmux
overwrite_with_symlink "${CONFIG_HOME}/_tmux.conf" "${HOME}/.tmux.conf"
# tmux plugins
mkdir -p "${HOME}/.tmux/plugins"
overwrite_with_symlink "${CONFIG_HOME}/tmux-wifiorethernet" "${HOME}/.tmux/plugins/tmux-wifiorethernet"
clone_repo "https://github.com/fcsonline/tmux-thumbs.git"
overwrite_with_symlink "${HOME}/code/tmux-thumbs" "${HOME}/.tmux/plugins/tmux-thumbs"
clone_repo "https://github.com/tmux-plugins/tmux-cpu.git"
overwrite_with_symlink "${HOME}/code/tmux-cpu" "${HOME}/.tmux/plugins/tmux-cpu"
clone_repo "https://github.com/purajit/tmux-battery.git"
overwrite_with_symlink "${HOME}/code/tmux-battery" "${HOME}/.tmux/plugins/tmux-battery"
printf "│ %s%s Terraform plugins installed\n" "${GREEN}" "${RESET}"
if [ -n "$TMUX" ]; then
tmux source "${HOME}/.tmux.conf"
printf "│ %s%s Active tmux session updated to latest configs\n" "${GREEN}" "${RESET}"
fi
# Alacritty
overwrite_with_symlink "${CONFIG_HOME}/alacritty.toml" "${HOME}/.config/alacritty.toml"
# Alacritty dynamic theming
mkdir -p "$HOME/.config/alacritty"
rm -rf "$HOME/.config/alacritty/active_theme.toml"
overwrite_with_symlink "${CONFIG_HOME}/alacritty_dark.toml" "$HOME/.config/alacritty/dark.toml"
overwrite_with_symlink "${CONFIG_HOME}/alacritty_light.toml" "$HOME/.config/alacritty/light.toml"
# Replace icon
rm /Applications/Alacritty.app/Contents/Resources/alacritty.icns
cp "${CONFIG_HOME}/alacritty.icns" /Applications/Alacritty.app/Contents/Resources/alacritty.icns
touch /Applications/Alacritty.app
printf "│ %s%s Replaced Alacritty icon\n" "${GREEN}" "${RESET}"
}
function setup_automation {
printf "%s Automation tools%s\n" "${YELLOW}" "${RESET}"
overwrite_with_symlink "${CONFIG_HOME}/_hammerspoon" "${HOME}/.hammerspoon"
}
function setup_emacs {
printf "%s Emacs%s\n" "${YELLOW}" "${RESET}"
rm -f "${HOME}/.emacs" "${HOME}/.emacs.d"
DONT_PULL=1 clone_repo "https://github.com/hlissner/doom-emacs.git"
overwrite_with_symlink "${HOME}/code/doom-emacs" "${HOME}/.config/emacs"
"${HOME}/.config/emacs/bin/doom" install
overwrite_with_symlink "${CONFIG_HOME}/doom" "${HOME}/.config/doom"
"${HOME}/.config/emacs/bin/doom" sync
printf "│ %s%s Installed and sync'd doomemacs\n" "${GREEN}" "${RESET}"
}
function setup_git {
printf "%s Git%s\n" "${YELLOW}" "${RESET}"
overwrite_with_symlink "${CONFIG_HOME}/_gitconfig" "${HOME}/.gitconfig"
overwrite_with_symlink "${CONFIG_HOME}/_gitignore_global" "${HOME}/.gitignore_global"
}
function setup_defaults {
printf "%s defaults/plists%s\n" "${YELLOW}" "${RESET}"
defaults write org.p0deje.Maccy clipboardCheckInterval 2
printf "│ %s%s Increased Maccy check interval to 2s\n" "${GREEN}" "${RESET}"
defaults write com.apple.screencapture location "${HOME}/Documents/Screenshots"
mkdir -p "${HOME}/Documents/Screenshots"
printf "│ %s%s Screenshots will be stored in %s/Documents/Screenshots\n" "${GREEN}" "${RESET}" "${HOME}"
# at the end
killall SystemUIServer
killall Finder
killall Dock
printf "│ %s%s Restarted UI elements so certain changes go into effect\n" "${GREEN}" "${RESET}"
}
function setup_misc {
printf "%s m i s c 🦀%s\n" "${YELLOW}" "${RESET}"
if brew list rust &>/dev/null; then
brew uninstall rust
printf "│ %s%s Uninstalled Brew-maintained rust toolchain (in favor of rustup)\n" "${GREEN}" "${RESET}"
fi
if command -v cargo &>/dev/null; then
printf "│ %s%s Rust 🦀 toolchain already installed\n" "${GREEN}" "${RESET}"
else
printf "│ %s %s Running rustup\n" "${YELLOW}" "${RESET}"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
fi
mkdir -p "${HOME}/.ipython/profile_default/"
overwrite_with_symlink "${CONFIG_HOME}/ipython_config.py" "${HOME}/.ipython/profile_default/ipython_config.py"
mkdir -p "${HOME}/.config/gh-dash"
overwrite_with_symlink "${CONFIG_HOME}/gh-dash-config.yml" "${HOME}/.config/gh-dash/config.yml"
mkdir -p "${HOME}/.config/wtf"
overwrite_with_symlink "${CONFIG_HOME}/wtfutil-config.yml" "${HOME}/.config/wtf/config.yml"
mkdir -p "${HOME}/.ssh"
overwrite_with_symlink "${CONFIG_HOME}/ssh_config" "${HOME}/.ssh/config"
overwrite_with_symlink "${CONFIG_HOME}/_terraformrc" "${HOME}/.terraformrc"
mkdir -p "${HOME}/.terraform.d/plugin-cache"
printf "│ %s%s Created Terraform global plugin cache\n" "${GREEN}" "${RESET}"
}
ALL_MODULES=(
"init"
# first, a package manager
"brew"
# then, the shell, terminal, editor, basic automation
"shell"
"automation"
"emacs"
# the rest
"git"
"defaults"
"misc"
)
if [[ "$#" == 1 && "$1" == "all" ]]; then
modules=("${ALL_MODULES[@]}")
else
modules=("init" "$@")
fi
for module in "${modules[@]}"; do
printf "╭─ "
bad_module=false
if [ "$module" = "init" ]; then
setup_init
elif [ "$module" = "brew" ]; then
setup_brew
elif [ "$module" = "shell" ]; then
setup_shell
elif [ "$module" = "automation" ]; then
setup_automation
elif [ "$module" = "emacs" ]; then
setup_emacs
elif [ "$module" = "git" ]; then
setup_git
elif [ "$module" = "defaults" ]; then
setup_defaults
elif [ "$module" = "misc" ]; then
setup_misc
else
printf "\n╰─ %sUnknown module %s :c%s\n" "${RED}" "${module}" "${RESET}"
bad_module=true
fi
if [ "$bad_module" = "false" ]; then
printf "╰─ %sFinished!%s\n\n" "${GREEN}" "${RESET}"
fi
done
printf "\nAll done!"