-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathlink.sh
executable file
·169 lines (129 loc) · 4.25 KB
/
link.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
#!/usr/bin/env bash
# Unofficial Bash "strict mode"
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
#ORIGINAL_IFS=$IFS
IFS=$'\t\n' # Stricter IFS settings
# This script creates symlinks from the home directory to any desired dotfiles
# in ~/dotfiles
# Variables
# The border for headings printed to STDOUT
border="====="
# Dotfiles directory
dotfiles=$HOME/dotfiles
# List of space separated files/folders to symlink in homedir (these are the typical "dotfiles")
files="vimrc vim zshrc bashrc tmux.conf gitignore_global ctags screenrc \
jshintrc rsync-exclude tool-versions agignore asdfrc psqlrc hushlogin \
my.cnf inputrc editrc iex.exs curlrc irbrc gemrc ripgrep-ignore \
gitattributes gnuplot digrc"
# Functions
error_exit() {
printf "\e[1;7;31m'%s\n\e[0m" "$1" 1>&2
exit "${2:-1}" # default exit status 1
}
print_heading() {
local text=$1
echo "$border $text $border"
}
make_dir_if_missing() {
local directory=$1
if [ ! -d "$directory" ]; then
mkdir "$directory"
fi
}
remove_dir_if_exists() {
local directory=$1
if [ -d "$directory" ]; then
rm -rf "$directory"
fi
}
symlink_file_if_missing() {
local source=$1
local destination=$2
if [ ! -f "$destination" ]; then
ln -nfs "$source" "$destination"
fi
}
create_or_replace_symlink() {
local source=$1
local destination=$2
if [ -L "$destination" ]; then
rm "$destination"
fi
ln -nfs "$source" "$destination"
}
symlink() {
local source=$1
local destination=$2
if [ -e "$destination" ] || [ -L "$destination" ]; then
echo "Removing $(basename "$destination") from $HOME"
rm "$destination";
fi
echo "Symlinking $destination -> $source"
ln -s "$source" "$destination"
}
create_or_replace_symlinks() {
local directory=$1
local destination=$2
scripts="$(find "$directory" -maxdepth 1 -type f \( -perm -u=x \) -print)"
IFS=$'\n'
for script in $scripts; do
create_or_replace_symlink "$script" "$destination"
done
IFS=$ORIGINAL_IFS
}
print_heading "Linking Dotfiles"
# create symlinks
ORIGINAL_IFS=$IFS
IFS=$' '
for file in $files; do
symlink "$dotfiles/$file" "$HOME/.$file"
done
IFS=$ORIGINAL_IFS
# Generate and copy gitconfig
"$dotfiles/scripts/generate_gitconfig.sh"
# Generate ripgrep config with absolute paths since ripgrep can't handle ~ or
# shell variables
"$dotfiles/scripts/generate_ripgreprc.sh"
# setup default tmuxinator project
make_dir_if_missing "$HOME/.tmuxinator"
# Create directory for Vim undo history
make_dir_if_missing "$dotfiles/vim/undodir"
# link the default tmuxinator project
symlink "$dotfiles/tmuxinator/default.yml" "$HOME/.tmuxinator/default.yml"
# Symlink the .erlang file
symlink "$dotfiles/erlang/erlang" "$HOME/.erlang"
# Symlink all the executable scripts in scripts/tools to the bin directory
create_or_replace_symlinks "$dotfiles/scripts/tools" "$HOME/bin"
# Symlink all the scripts in scripts/git to the bin directory
create_or_replace_symlinks "$dotfiles/scripts/git" "$HOME/bin"
# Some scripts are only needed on MacOS or Linux
if [ "$(uname)" == "Darwin" ]; then
create_or_replace_symlinks "$dotfiles/scripts/tools/macos" "$HOME/bin"
fi
if [ "$(uname)" == "Linux" ]; then
create_or_replace_symlinks "$dotfiles/scripts/tools/linux" "$HOME/bin"
fi
if [ "$(uname)" == "Darwin" ]; then
symlink "$dotfiles/templates/k9s/skin.yml" "$HOME/Library/Application Support/k9s/skin.yml"
else
echo "Cannot link k9s skin"
fi
# Download Vundle if not already downloaded
print_heading "Installing Vundle"
vundle_dir="$dotfiles/vim/bundle/Vundle.vim"
if [ ! -d "$vundle_dir" ]; then
git clone https://github.com/gmarik/Vundle.vim.git "$vundle_dir"
else
echo "Vundle already installed"
fi
# Validate Vim was compiled with flags needed by plugins
vim_info="$(vim --version)"
grep -F '+float' <<< "$vim_info" > /dev/null ||
error_exit "Vim not compiled with +float option needed for the crunch plugin. Please recompile"
grep -F '+python' <<< "$vim_info" > /dev/null ||
error_exit "Vim not compiled with +python option needed for the ultisnips plugin. Please recompile"
# Install Vundle and all other plugins
print_heading "Installing Vim Plugins"
vim +PluginInstall +qall
print_heading "Linking and Vim Configuration Complete"