-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·283 lines (236 loc) · 7.19 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·283 lines (236 loc) · 7.19 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
#!/bin/bash
# Utils
function is_installed {
# set to 1 initially
local return_=1
# set to 0 if not found
type $1 >/dev/null 2>&1 || { local return_=0; }
# return
echo "$return_"
}
function install_nvm {
if [ "$(is_installed nvm)" == "0" ] && [ ! -s "$HOME/.nvm/nvm.sh" ]; then
echo "Installing nvm"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
echo "Please run 'nvm install --lts' to install the latest LTS version of Node.js"
fi
}
function install_oh_my_zsh {
if [[ ! -d ~/.oh-my-zsh ]]; then
echo "Installing oh-my-zsh"
unset ZSH
RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
local zsh_custom="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
if [ ! -d "$zsh_custom/plugins/zsh-autosuggestions" ]; then
echo "Installing zsh-autosuggestions"
git clone https://github.com/zsh-users/zsh-autosuggestions "$zsh_custom/plugins/zsh-autosuggestions"
fi
}
function install_macos {
if [[ $OSTYPE != darwin* ]]; then
return
fi
echo "MacOS detected"
xcode-select --install
if [ "$(is_installed brew)" == "0" ]; then
echo "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if [ ! -d "/Applications/iTerm.app" ]; then
echo "Installing iTerm2"
brew tap homebrew/cask
brew install iterm2 --cask
fi
if [ "$(is_installed zsh)" == "0" ]; then
echo "Installing zsh"
brew install zsh zsh-completions
fi
install_oh_my_zsh
if [ "$(is_installed rg)" == "0" ]; then
echo "Installing ripgrep"
brew install ripgrep
fi
if [ "$(is_installed fzf)" == "0" ]; then
echo "Installing fzf"
brew install fzf
/opt/homebrew/opt/fzf/install
fi
if [ "$(is_installed tmux)" == "0" ]; then
echo "Installing tmux"
brew install tmux
echo "Installing reattach-to-user-namespace"
brew install reattach-to-user-namespace
echo "Installing tmux-plugin-manager"
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
fi
if [ "$(is_installed git)" == "0" ]; then
echo "Installing Git"
brew install git
fi
if [ "$(is_installed gh)" == "0" ]; then
echo "Installing Github CLI"
brew install gh
fi
if [ "$(is_installed nvim)" == "0" ]; then
echo "Install neovim"
brew install neovim
if [ "$(is_installed pip3)" == "1" ]; then
pip3 install neovim --upgrade
fi
fi
}
function install_linux {
if [[ $OSTYPE != linux* ]]; then
return
fi
echo "Linux detected"
if [ "$(is_installed apt-get)" != "1" ]; then
echo "Only apt-based Linux distributions are supported by this installer."
exit 1
fi
local packages=()
[ "$(is_installed curl)" == "0" ] && packages+=(curl)
[ "$(is_installed git)" == "0" ] && packages+=(git)
[ "$(is_installed zsh)" == "0" ] && packages+=(zsh)
[ "$(is_installed fzf)" == "0" ] && packages+=(fzf)
[ "$(is_installed tmux)" == "0" ] && packages+=(tmux)
[ "$(is_installed nvim)" == "0" ] && packages+=(neovim)
[ "$(is_installed rg)" == "0" ] && packages+=(ripgrep)
[ "$(is_installed pip3)" == "0" ] && packages+=(python3-pip)
if [ ${#packages[@]} -gt 0 ]; then
echo "Installing Linux packages: ${packages[*]}"
sudo apt-get update
sudo apt-get install -y "${packages[@]}"
fi
install_oh_my_zsh
if [ ! -d "$HOME/.tmux/plugins/tpm" ]; then
echo "Installing tmux-plugin-manager"
git clone https://github.com/tmux-plugins/tpm "$HOME/.tmux/plugins/tpm"
fi
if [ "$(is_installed pip3)" == "1" ]; then
pip3 install --user neovim --upgrade
fi
install_nvm
}
function install_dependencies {
install_macos
install_linux
}
function backup {
echo "Backing up dotfiles"
local current_date=$(date +%s)
local backup_dir=dotfiles_$current_date
mkdir ~/$backup_dir
[ -e ~/.zshrc ] && mv ~/.zshrc ~/$backup_dir/.zshrc
[ -e ~/.tmux.conf ] && mv ~/.tmux.conf ~/$backup_dir/.tmux.conf
[ -e ~/.vim ] && mv ~/.vim ~/$backup_dir/.vim
[ -e ~/.vimrc ] && mv ~/.vimrc ~/$backup_dir/.vimrc
[ -e ~/.vimrc.bundles ] && mv ~/.vimrc.bundles ~/$backup_dir/.vimrc.bundles
}
function link_dotfiles {
echo "Removing existing config"
rm -rf $HOME/.config/nvim/init.vim
rm -rf $HOME/.config/nvim
rm -rf $HOME/.vim/bundle/*
echo "Linking dotfiles"
ln -sf "$(pwd)/zshrc" ~/.zshrc
ln -sf "$(pwd)/tmux.conf" ~/.tmux.conf
echo "Creating vim symlinks"
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
mkdir -p "$HOME/.vim"
ln -sf "$(pwd)/vim/coc-settings.json" "$HOME/.vim/coc-settings.json"
ln -sf "$(pwd)/vimrc" "$HOME/.vimrc"
ln -sf "$(pwd)/vimrc" "$HOME/.vim/init.vim"
ln -sf "$(pwd)/vimrc.bundles" ~/.vimrc.bundles
mkdir -p ${XDG_CONFIG_HOME:=$HOME/.config}
ln -sfn "$HOME/.vim" "$XDG_CONFIG_HOME/nvim"
if [[ ! -f ~/.zshrc.local ]]; then
echo "Creating .zshrc.local"
touch ~/.zshrc.local
fi
}
function install_theme {
echo "Installing theme"
mkdir -p "$HOME/.oh-my-zsh/themes"
ln -sf "$(pwd)/schemes/dracula.zsh-theme" "$HOME/.oh-my-zsh/themes/dracula.zsh-theme"
echo 'ZSH_THEME="dracula"' > "$HOME/.zshrc.theme"
mkdir -p "$HOME/.vim"
ln -sfn "$(pwd)/vim/colors" "$HOME/.vim/colors"
echo 'colorscheme dracula' > "$HOME/.vimrc.theme"
if [[ $OSTYPE == darwin* ]]; then
echo "iTerm2 color scheme is available at $(pwd)/schemes/dracula.itermcolors"
fi
}
function post_install {
echo "Post install"
echo "Installing vim plugins"
vim +PlugClean +PlugInstall
echo "Installing coc plugins"
vim +"CocInstall coc-json coc-tsserver coc-html coc-css coc-yaml coc-python coc-clangd coc-cmake coc-deno coc-docker coc-eslint coc-flutter coc-fzf-preview coc-git coc-go coc-graphql coc-highlight coc-pairs coc-prettier coc-rust-analyzer coc-snippets coc-sql coc-tailwindcss"
echo "Install nvm"
install_nvm
}
function usage {
echo "Usage: ./install.sh [options]"
echo ""
echo "Options:"
echo " --macos Install macOS dependencies, dotfiles, and plugins"
echo " --linux Install Ubuntu dependencies and dotfiles"
echo " --deps Install dependencies for the current OS"
echo " --dotfiles Backup existing files and link dotfiles only"
echo " --theme Install Dracula theme links and opt-in config"
echo " --backup Backup existing dotfiles only"
echo " --post-install Install vim/coc plugins and nvm"
echo " --help Show this help"
}
while test $# -gt 0; do
case "$1" in
--help)
usage
exit
;;
--macos)
install_macos
backup
link_dotfiles
post_install
zsh
source ~/.zshrc
exit
;;
--linux)
install_linux
backup
link_dotfiles
zsh
source ~/.zshrc
exit
;;
--deps)
install_dependencies
exit
;;
--backup)
backup
exit
;;
--dotfiles)
backup
link_dotfiles
exit
;;
--theme)
install_theme
exit
;;
--post-install)
post_install
exit
;;
esac
shift
done
usage