-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·176 lines (158 loc) · 4.28 KB
/
install.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
#! /usr/local/bin/bash
pushd `dirname $0` > /dev/null
SCRIPT_PATH=`pwd`
popd > /dev/null
HOMEBREW_PACKAGES=(
'bash'
'git'
'vim'
'tmux'
'reattach-to-user-namespace'
'zsh'
'jenv'
'the_silver_searcher'
'ruby-build'
'rbenv'
'fzf'
)
declare -A VIM_PACKAGE_REMOTES
VIM_PACKAGE_REMOTES=(
[ctrlp.vim]='[email protected]:kien/ctrlp.vim.git'
[fzf.vim]='[email protected]:junegunn/fzf.vim.git'
[nerdtree]='[email protected]:scrooloose/nerdtree.git'
[supertab]='[email protected]:ervandew/supertab.git'
[typescript-vim]='[email protected]:leafgarland/typescript-vim.git'
[vim-airline-themes]='[email protected]:vim-airline/vim-airline-themes.git'
[vim-airline]='[email protected]:vim-airline/vim-airline.git'
[vim-colors-solarized]='[email protected]:altercation/vim-colors-solarized.git'
[vim-fugitive]='[email protected]:tpope/vim-fugitive.git'
[vim-ruby]='[email protected]:vim-ruby/vim-ruby.git'
[vim-unimpaired]='[email protected]:tpope/vim-unimpaired.git'
)
install_brew_package() {
pkg_name=$1
if brew ls --versions $pkg_name > /dev/null;
then
echo "$pkg_name already installed; skipping"
else
if $DRY_RUN;
then
echo "Would have installed $pkg_name, but --dry-run was enabled"
else
brew install $pkg_name
fi
fi
}
install_vim_package() {
package_name=$1
git_remote=${VIM_PACKAGE_REMOTES[$package_name]}
exec 3>&2
exec 2> /dev/null
ls -H "$HOME/.vim/bundle/$package_name" > /dev/null
if [[ $? != 0 ]];
then
git clone --quiet $git_remote "$HOME/.vim/bundle/$package_name"
else
echo "$git_remote was already installed"
fi
exec 2>&3
}
link_and_backup_dotfile() {
filename=$1
pathname="$HOME/$filename"
exec 3>&2
exec 2> /dev/null
ls -H $pathname > /dev/null
if [[ $? != 0 ]];
then
if $DRY_RUN;
then
echo "Would have linked $filename to $pathname but --dry-run was enabled"
else
link_dotfile $filename
fi
else
backup_pathname="$pathname.bak"
if $DRY_RUN;
then
echo "Would have moved $pathname to $backup_pathname and linked $filename to $pathname but --dry-run was enabled"
else
backup_dotfile $filename
link_dotfile $filename
fi
fi
exec 2>&3
}
backup_dotfile() {
filename=$1
pathname="$HOME/$filename"
backup_pathname="$pathname.bak"
mv $pathname $backup_pathname
}
link_dotfile() {
filename=$1
target="$HOME/$filename"
echo "Linking $SCRIPT_PATH/$filename to $target"
ln -s "$SCRIPT_PATH/$filename" $target
}
DRY_RUN=false
OPTS=`getopt -o d: --long dry-run -n 'install.sh' --"$@"`
while [ "$1" != "" ]; do
case $1 in
-d|--dry-run)
DRY_RUN=true; shift;;
*)
;;
esac
done
export PATH=/usr/local/bin:$PATH
which -s brew
if [[ $? != 0 ]];
then
if $DRY_RUN;
then
echo 'Would have installed brew, but --dry-run was enabled'
else
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
else
echo 'brew already installed; skipping'
fi
if brew ls --versions zsh > /dev/null;
then
echo 'zsh already installed; not installing oh-my-zsh'
else
if $DRY_RUN;
then
echo 'Would have installed oh-my-zsh, but --dry-run was enabled'
else
font_path = "$SCRIPT_PATH/Inconsolata-dz for Powerline Nerd Font Complete Mono.otf"
curl -L 'https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/Inconsolata/complete/Inconsolata%20Nerd%20Font%20Complete%20Mono.otf' > $font_path
open $font_path
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
fi
fi
# Install all homebrew packages
for pkg in "${HOMEBREW_PACKAGES[@]}"
do
install_brew_package $pkg
done
# Link all dotfiles
mkdir -p "$HOME/.vim/bundle"
# Install all vim packages
mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
for package_name in "${!VIM_PACKAGE_REMOTES[@]}"
do
install_vim_package $package_name
done
# Backup and link all the dotfiles
link_and_backup_dotfile '.bash'
link_and_backup_dotfile '.gitconfig'
link_and_backup_dotfile '.gitk'
link_and_backup_dotfile '.tmux.conf'
link_and_backup_dotfile '.vim'
link_and_backup_dotfile '.vimrc'
link_and_backup_dotfile '.zshrc'
link_and_backup_dotfile '.localrc'