-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-zsh.sh
executable file
·306 lines (260 loc) · 8.57 KB
/
install-zsh.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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"
backup_file () {
local file="$1"
# regular file and not a symlink
# https://tldp.org/LDP/abs/html/fto.html
if [ -f "$file" ] && [ ! -h "$file" ]; then
mv "$file" "$file.bak"
echo " --- Backed up: $file"
fi
}
link_file () {
local source="$1"
local dest="$2"
mkdir -p "$(dirname "$dest")"
ln -sf "$source" "$dest"
echo " --- Linked: $source to $dest"
}
copy_file () {
local source="$1"
local dest="$2"
mkdir -p "$(dirname "$dest")"
cp -f "$source" "$dest"
echo " --- Copied: $source to $dest"
}
ensure_repo () {
local name="$1"
local repo="$2"
local dest="$3"
if [ -d "$dest" ]; then
echo "###### Updating $name"
git -C "$dest" pull
else
echo "###### Cloning $name"
git clone --depth 1 "$repo" "$dest"
fi
}
ensure_brew () {
brew upgrade $1 ${2:-} --no-quarantine || brew install $1 ${2:-} --no-quarantine
}
ensure_font () {
local release=$1
local name=$2
wget \
--output-document "/tmp/${name}.zip" \
"https://github.com/ryanoasis/nerd-fonts/releases/download/${release}/${name}.zip"
unzip -o "/tmp/${name}.zip" -d ~/.local/share/fonts
}
sudo_cmd () {
if [ "$(id -u)" = "0" ]; then
echo ''
elif command -v sudo; then
echo 'sudo'
fi
}
install_dpkg () {
local url="${1}"
local filename
filename=$(basename "$url")
local Sudo
Sudo=$(sudo_cmd)
(cd /tmp && curl -LO "$url")
$Sudo dpkg -i "/tmp/${filename}"
}
file_exists_indicator () {
file="${1:-}"
if [[ -f "$file" ]]; then
printf "\033[1;32m✔\033[0m"
else
printf "\033[1;31m✘\033[0m"
fi
}
init () {
OS="$(uname)"
case $OS in
Darwin)
arch_name="$(uname -m)"
if [ "$arch_name" = "x86_64" ]; then
if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]; then
echo "ERROR: Running on Rosetta 2"
echo ""
echo "Re-run this as:"
echo " arch -arm64 $0"
echo ""
exit 1
else
echo "Running on native Intel"
fi
elif [ "$arch_name" = "arm64" ]; then
echo "Running on ARM"
else
echo "Unknown architecture: ${arch_name}"
fi
echo "##### Install Apple Command Line Tools"
xcode-select --install || true
if [[ -f /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
if [[ -f /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
echo "###### Installing OSX Dependencies"
ensure_brew bat
ensure_brew direnv
ensure_brew docker
ensure_brew eza
ensure_brew fd
ensure_brew git
ensure_brew git-delta
ensure_brew htop
ensure_brew jq
ensure_brew maestral
ensure_brew pyenv
ensure_brew rnr
ensure_brew ripgrep
ensure_brew the_silver_searcher
ensure_brew tmux
ensure_brew vim
ensure_brew zx
# Keep homebrew up to date
ensure_brew terminal-notifier
brew tap domt4/autoupdate
brew autoupdate --start || true
# NerdFonts
ensure_brew --cask font-meslo-lg-nerd-font
# UI Programs
ensure_brew --cask alacritty || true
ensure_brew --cask brave-browser || true
ensure_brew --cask bitwarden || true
ensure_brew bitwarden-cli || true
ensure_brew --cask boop || true
ensure_brew --cask cyberduck || true
ensure_brew --cask slack || true
ensure_brew --cask spotify || true
ensure_brew --cask sonos || true
ensure_brew --cask tunnelblick || true
ensure_brew --cask vlc || true
ensure_brew --cask zoom || true
# OSX Settings
./install-osx.sh
;;
Linux)
echo "###### Installing Linux Dependencies"
local Sudo
Sudo=$(sudo_cmd)
arch_name="$(uname -m)"
if [ "$arch_name" = "x86_64" ]; then
echo "Running on x86"
install_dpkg https://github.com/sharkdp/bat/releases/download/v0.24.0/bat_0.24.0_amd64.deb
# libgcc-s1 >= 4.2 is needed for delta on 18.04
$Sudo apt-get install -y libgcc-s1
install_dpkg https://github.com/dandavison/delta/releases/download/0.17.0/git-delta_0.17.0_amd64.deb
install_dpkg https://github.com/sharkdp/fd/releases/download/v9.0.0/fd_9.0.0_amd64.deb
install_dpkg https://github.com/BurntSushi/ripgrep/releases/download/14.1.0/ripgrep_14.1.0-1_amd64.deb
elif [ "$arch_name" = "aarch64" ]; then
echo "Running on ARM"
install_dpkg https://github.com/sharkdp/bat/releases/download/v0.24.0/bat_0.24.0_arm64.deb
# libgcc-s1 >= 4.2 is needed for delta on 18.04
$Sudo apt-get install -y libgcc-s1
install_dpkg https://github.com/dandavison/delta/releases/download/0.17.0/git-delta_0.17.0_arm64.deb
install_dpkg https://github.com/sharkdp/fd/releases/download/v9.0.0/fd_9.0.0_arm64.deb
else
echo "Unknown architecture: ${arch_name}"
fi
$Sudo apt-get install -y \
bat \
direnv \
fd \
git \
htop \
jq \
ripgrep \
silversearcher-ag \
unzip \
vim
mkdir -p ~/bin
if dpkg --compare-versions "$(lsb_release -sr)" 'le' '18.04' ; then
filename=tmux-3.0a-x86_64.AppImage
if [ -f $filename ]; then
(
cd ~/bin \
&& curl -LO https://github.com/nelsonenzo/tmux-appimage/releases/download/3.0a-appimage0.2.0/tmux-3.0a-x86_64.AppImage
)
fi
ln -sf ~/bin/$filename ~/bin/tmux
else
$Sudo apt-get install -y tmux
fi
(
cd /tmp \
&& curl -LO https://github.com/ogham/exa/releases/download/v0.10.1/exa-linux-x86_64-v0.10.1.zip \
&& unzip -o exa-linux-x86_64-v0.10.1.zip -d ~/bin
)
ln -sf ~/bin/exa-linux-x86_64 ~/bin/exa
# NerdFonts
echo "### Download fonts"
# ensure_font "v2.1.0" "Meslo"
if command -v fc-cache > /dev/null; then
fc-cache -fv
fi
;;
esac
echo "###### Linking templates/ to $HOME"
for source in $(find $(pwd)/templates -type f | sort -nr); do
dest="${source//$(pwd)\/templates/$HOME}"
backup_file "$dest"
link_file "$source" "$dest"
done
# Files which must be copied, not symlinked
rm -f "$HOME"/.tmux/version_* || true
copy_file "$(pwd)/templates/.tmux/version_1.9_down.conf" "$HOME/.tmux/version_1.9_down.conf"
copy_file "$(pwd)/templates/.tmux/version_1.9_to_2.1.conf" "$HOME/.tmux/version_1.9_to_2.1.conf"
copy_file "$(pwd)/templates/.tmux/version_2.1_up.conf" "$HOME/.tmux/version_2.1_up.conf"
copy_file "$(pwd)/templates/.tmux/version_2.3_up.conf" "$HOME/.tmux/version_2.3_up.conf"
echo "###### Generating config files"
for source in $(find "$(pwd)/generators" -type f | sort -nr); do
dest="${source//$(pwd)\/generators/$HOME}"
backup_file "$dest"
eval "$source" > "$dest"
echo " --- Generated: $dest"
done
# Install or update fzf
ensure_repo "fzf" https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install --key-bindings --completion --no-update-rc
ensure_repo "Tmux Theme (clone)" https://github.com/ryan953/tmux-onedark-theme.git ~/.tmux/tmux-onedark-theme
ensure_repo "Tmux Sensible" https://github.com/tmux-plugins/tmux-sensible ~/.tmux/tmux-sensible
ensure_repo "Tmux Prefix Highlight" https://github.com/tmux-plugins/tmux-prefix-highlight.git ~/.tmux/tmux-prefix-highlight
ensure_repo "Tmux fzf" https://github.com/sainnhe/tmux-fzf ~/.tmux/tmux-fzf
# Install or update vundle (depends on vim)
ensure_repo "Vundle" https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PluginInstall +qall
# File dependency for `z` antigen plugin (see .antigenrc)
touch ~/.z
# Allow zsh, then change the default
case $OS in
Darwin)
zsh_path=$(command -v zsh)
if [[ $(dscl . -read ~/ UserShell | sed 's/UserShell: //') == $zsh_path ]]; then
echo "Shell set to $zsh_path"
else
sudo sh -c "echo $zsh_path >> /etc/shells"
chsh -s "$zsh_path"
fi
;;
Linux)
;;
esac
echo "###### Done"
echo ""
echo "You can extend this setup by editing these files:"
echo " $(file_exists_indicator "$HOME/.zprofile") ~/.zprofile then start a new zsh session"
echo " $(file_exists_indicator "$HOME/.gitconfig.local") ~/.gitconfig.local"
echo " $(file_exists_indicator "$HOME/.ssh/config.local") ~/.ssh/config.local"
echo ""
# https://github.com/romkatv/powerlevel10k/blob/master/README.md#weird-things-happen-after-typing-source-zshrc
echo "Start a new zsh session to load changes. (new tab, or run $(command -v zsh))"
}
init