-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
228 lines (173 loc) · 6.47 KB
/
installer.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
#!/usr/bin/env bash
#==============================================================================
# title : installer.sh
# description : Installer script for these configurations
# author : Adi Iyengar
# username : aditya7iyengar
# date_created : 2017-02-01
# version : 0.9
# usage : $ bash <filename or wget url>
# notes : This scripts installs tools for these configurations
# versions : Tmux 2.x, Zsh 5.x
#==============================================================================
REPO_URL="https://github.com/aditya7iyengar/dotfiles"
# path where dotfiles will be cloned
DOTFILES_PATH="$HOME/.dotfiles"
# path where custom dotfiles will be cloned
DOTFILES_CUSTOM_PATH="$HOME/.dotfiles.custom"
# Prints main steps of this installer
_print_step() {
echo -e """
==========================================================
$1..
==========================================================
"""
}
# Git clone configurations
clone_repo() {
_print_step "Cloning Repo"
git clone $REPO_URL $DOTFILES_PATH
}
# Clone custom repo
clone_custom_repo() {
_print_step "Cloning Custom Repo"
if ! [[ -z $CUSTOM_REPO_URL ]]; then
git clone $CUSTOM_REPO_URL $DOTFILES_CUSTOM_PATH
CUSTOM_DOTFILES_GIVEN=1
elif ! [[ -z $CUSTOM_LOCAL_PATH ]]; then
cp -r $CUSTOM_LOCAL_PATH $DOTFILES_CUSTOM_PATH
CUSTOM_DOTFILES_GIVEN=1
else
echo "No CUSTOM_REPO_URL given"
fi
}
# Installs Oh my zsh
install_oh_my_zsh() {
_print_step "Installing Oh My Zsh"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
}
# Creates a symbolic link from source to destination
# Preserves old version of destination pre installation process with a suffix `.pre-dotfiles`
_symlink() {
source_path=$1
destination_path=$2
# Link only if source path exists
if [[ -e $source_path ]]; then
# Preserve dotfiles pre installation process
if [[ -e $destination_path ]]; then
mv $destination_path "${destination_path}.pre-dotfiles"
fi
ln -sf $source_path $destination_path
fi
}
# Creates symbolic links for all zsh files
_symlink_zsh_files() {
_symlink $DOTFILES_PATH/.zshrc $HOME/.zshrc
destination_directory="$HOME/.zshrc-components"
source_directory="$DOTFILES_PATH/.zshrc-components"
# Preserve previous $HOME/.zshrc-components directory if it exists
if [[ -e $destination_directory ]]; then
mv $destination_directory "${destination_directory}.pre-dotfiles"
fi
# Create $HOME/.zsh directory
mkdir $destination_directory
_symlink $source_directory/exports.sh $destination_directory/exports.sh
_symlink $source_directory/aliases.sh $destination_directory/aliases.sh
# Custom
if ! [[ -z $CUSTOM_DOTFILES_GIVEN ]]; then
_symlink $DOTFILES_CUSTOM_PATH/.zshrc-components/custom.sh $destination_directory/custom.sh
fi
# Languages & Tools
_symlink $source_directory/asdf.sh $destination_directory/asdf.sh
_symlink $source_directory/asdf.elixir.sh $destination_directory/asdf.elixir.sh
_symlink $source_directory/asdf.rust.sh $destination_directory/asdf.rust.sh
_symlink $source_directory/asdf.ruby.sh $destination_directory/asdf.ruby.sh
_symlink $source_directory/asdf.go.sh $destination_directory/asdf.go.sh
_symlink $source_directory/asdf.direnv.sh $destination_directory/asdf.direnv.sh
_symlink $source_directory/asdf.nvim.sh $destination_directory/asdf.nvim.sh
_symlink $source_directory/fasd.sh $destination_directory/fasd.sh
}
_install_vundle() {
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PluginInstall +qall -c ":q"
}
_symlink_nvim_files() {
_symlink $DOTFILES_PATH/.vimrc $HOME/.vimrc
destination_directory="$HOME/.vimrc-components"
source_directory="$DOTFILES_PATH/.vimrc-components"
# Preserve previous $HOME/.vimrc-components directory if it exists
if [[ -e $destination_directory ]]; then
mv $destination_directory "${destination_directory}.pre-dotfiles"
fi
# Create $HOME/.zsh directory
mkdir $destination_directory
# General Vim Config
_symlink $source_directory/gen-config.vim $destination_directory/gen-config.vim
# Custom Vim
if ! [[ -z $CUSTOM_DOTFILES_GIVEN ]]; then
_symlink $DOTFILES_CUSTOM_PATH/.vimrc-components/custom.vim $destination_directory/custom.vim
fi
# Vundle (Plugin Manager)
_symlink $source_directory/vundle.vim $destination_directory/vundle.vim
# Languages
_symlink $source_directory/languages.vim $destination_directory/languages.vim
# Functions and Mappings
_symlink $source_directory/mappings.vim $destination_directory/mappings.vim
_print_step "Installing Vundle"
_install_vundle
# Update system neovim to use vim config
mkdir -p $HOME/.config/nvim/colors
# Symlink nvim files to use vim configurations
_symlink $DOTFILES_PATH/.config/nvim/init.vim $HOME/.config/nvim/init.vim
_symlink $DOTFILES_PATH/.config/nvim/rplugin.vim $HOME/.config/nvim/rplugin.vim
_symlink $DOTFILES_PATH/.config/nvim/colors/NeoSolarized.vim $HOME/.config/nvim/colors/NeoSolarized.vim
# Update plugins for nvim
_print_step "Updating Remote plugins for neovim"
nvim +UpdateRemotePlugins +qall -c ":q"
}
# Creates symbolic link for .tmux.conf file
_symlink_tmux_files() {
_symlink $DOTFILES_PATH/.tmux.conf $HOME/.tmux.conf
}
_symlink_git_files() {
# User specific git configs
if ! [[ -z $CUSTOM_DOTFILES_GIVEN ]]; then
_symlink $DOTFILES_CUSTOM_PATH/.gitconfig $HOME/.gitconfig
mkdir $HOME/.git-components
# TODO: Move these to custom installer
_symlink $DOTFILES_CUSTOM_PATH/.git-components/commit-template $HOME/.git-components/commit-template
_symlink $DOTFILES_CUSTOM_PATH/.git-components/.gitignore $HOME/.git-components/.gitignore
fi
}
_symlink_alacritty_files() {
_symlink $DOTFILES_PATH/alacritty.yml $HOME/alacritty.yml
}
# Creates symbolic link for all dotfiles to function
symlink_files() {
_print_step "Linking ZSH files"
_symlink_zsh_files
_print_step "Linking NeoVim files"
_symlink_nvim_files
_print_step "Linking Tmux files"
_symlink_tmux_files
_print_step "Linking Git files"
_symlink_git_files
_print_step "Linking Alacritty files"
_symlink_alacritty_files
}
run_custom_installer() {
_print_step "Running custom installer"
custom_installer_path=$DOTFILES_CUSTOM_PATH/installer.sh
if [[ -e $custom_installer_path ]]; then
bash $custom_installer_path
fi
}
# Main interface for this script
main() {
clone_repo
install_oh_my_zsh
clone_custom_repo
symlink_files
run_custom_installer
}
main