-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·139 lines (115 loc) · 3.17 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
#!/bin/sh
# https://github.com/junegunn/vim-plug
PLUG_VIM_URL="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
# https://github.com/ganwell/vim-hunspell-dicts
ask() {
printf "%s [yN]: " "$1"
read -r yn
if [ "$yn" = "y" ] || [ "$yn" = "Y" ]; then
return 0
fi
return 1
}
check_installed() {
printf " %s: " "$1"
if command -v "$1" >/dev/null 2>&1; then
echo "installed!"
else
echo "not installed!"
exit 1
fi
}
# Create a link named $2 to file $1.
# Overwrites existing links.
# Overwrites all other files only on user confirmation
create_link() {
file=$1
link_name=$2
printf " Link: %s -> %s\n" "$link_name" "$file"
if [ -h "$link_name" ]; then # is a symbolic link
rm "$link_name"
elif [ -e "$link_name" ]; then # other file exists
if ask " File \"$link_name\" exists! Do you want to overwrite it? "; then
if [ -d "$link_name" ]; then
rm -r "$link_name"
else
rm "$link_name"
fi
else
return
fi
fi
ln -s "$file" "$link_name"
}
download() {
name=$1
file_path=$2
url=$3
printf "Downloading %s\n" "$name"
printf " "
if [ -e "$file_path" ]; then
echo "Already downloaded!"
return
fi
if curl --silent --fail --location --output "$file_path" --create-dirs \
"$url"
then
echo "Downloaded!"
else
echo "Failed!"
exit 1
fi
}
##### MAIN #####
echo "Checking installs"
check_installed vim
check_installed zsh
check_installed git
echo
SCRIPT_DIR=$(cd "$(dirname "$0")" || exit 1; pwd)
echo "Creating links"
create_link "$SCRIPT_DIR/latexmkrc" ~/.latexmkrc
create_link "$SCRIPT_DIR/tmux.conf" ~/.tmux.conf
create_link "$SCRIPT_DIR/vim" ~/.vim
create_link "$SCRIPT_DIR/zsh" ~/.zsh
create_link "$SCRIPT_DIR/zsh/zprofile" ~/.zprofile
create_link "$SCRIPT_DIR/zsh/zshenv" ~/.zshenv
create_link "$SCRIPT_DIR/zsh/zshrc" ~/.zshrc
create_link "$SCRIPT_DIR/gitconfig" ~/.gitconfig
create_link "$SCRIPT_DIR/gitignore_global" ~/.gitignore_global
mkdir -p ~/.gnupg/
create_link "$SCRIPT_DIR/gnupg/gpg.conf" ~/.gnupg/gpg.conf
create_link "$SCRIPT_DIR/gnupg/gpg-agent.conf" ~/.gnupg/gpg-agent.conf
if [ "$(uname)" = "Darwin" ]
then
create_link "$SCRIPT_DIR/hammerspoon" ~/.hammerspoon
fi
echo
echo "Creating folders"
echo " Folder: ~/.vimundo"
[ ! -d ~/.vimundo ] && mkdir ~/.vimundo
echo
echo "Cloning ZSH completions"
if [ ! -d "$SCRIPT_DIR/zsh/completion/zsh-completions" ]
then
git clone https://github.com/zsh-users/zsh-completions \
"$SCRIPT_DIR/zsh/completion/zsh-completions"
else
echo " Already cloned!"
fi
echo
download "plug.vim" "$SCRIPT_DIR/vim/autoload/plug.vim" "$PLUG_VIM_URL"
echo
echo "Installing Vim plugins"
vim_install_type_path=vim/autoload/installType.vim
if [ ! -e $vim_install_type_path ]; then
if ask " Install all vim plugins?"; then
echo "let g:installType#isCompleteInstall = 1" > $vim_install_type_path
else
echo "let g:installType#isCompleteInstall = 0" > $vim_install_type_path
fi
fi
vim +PlugInstall +sleep4 +qa
echo " Done!"
echo
echo "Finished!"