-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·193 lines (162 loc) · 4.98 KB
/
install
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
#!/usr/bin/env bash
set -e
DOTFILES="$(pwd)"
COLOR_GRAY="\033[1;38;5;243m"
COLOR_BLUE="\033[1;34m"
COLOR_GREEN="\033[1;32m"
COLOR_RED="\033[1;31m"
COLOR_PURPLE="\033[1;35m"
COLOR_YELLOW="\033[1;33m"
COLOR_NONE="\033[0m"
title() {
echo -e "\n${COLOR_PURPLE}$1${COLOR_NONE}"
echo -e "${COLOR_GRAY}==============================${COLOR_NONE}\n"
}
error() {
echo -e "${COLOR_RED}Error: ${COLOR_NONE}$1"
exit 1
}
warning() {
echo -e "${COLOR_YELLOW}Warning: ${COLOR_NONE}$1"
}
info() {
echo -e "${COLOR_BLUE}Info: ${COLOR_NONE}$1"
}
success() {
echo -e "${COLOR_GREEN}$1${COLOR_NONE}"
}
get_linkables() {
find -H "$DOTFILES" -maxdepth 3 -name '*.symlink'
}
backup() {
BACKUP_DIR=$HOME/dotfiles-backup
echo "Creating backup directory at $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
for file in $(get_linkables); do
filename="$(basename "$file" '.symlink')"
target="$HOME/$filename"
if [ -f "$target" ]; then
echo "backing up $filename"
cp "$target" "$BACKUP_DIR"
else
warning "$filename does not exist at this location or is a symlink"
fi
done
for filename in "$HOME/.config/nvim" "$HOME/.vim" "$HOME/.vimrc"; do
if [ ! -L "$filename" ]; then
echo "backing up $filename"
cp -rf "$filename" "$BACKUP_DIR"
else
warning "$filename does not exist at this location or is a symlink"
fi
done
}
setup_symlinks() {
title "Creating symlinks"
for file in $(get_linkables) ; do
target="$HOME/$(basename "$file" '.symlink')"
if [ -e "$target" ]; then
info "~${target#$HOME} already exists... Skipping."
else
info "Creating symlink for $file"
ln -s "$file" "$target"
fi
done
echo -e
info "installing to ~/.config"
if [ ! -d "$HOME/.config" ]; then
info "Creating ~/.config"
mkdir -p "$HOME/.config"
fi
config_files=$(find "$DOTFILES/config" -maxdepth 1 2>/dev/null)
for config in $config_files; do
target="$HOME/.config/$(basename "$config")"
if [ -e "$target" ]; then
info "~${target#$HOME} already exists... Skipping."
else
info "Creating symlink for $config"
ln -s "$config" "$target"
fi
done
bin_files=$(find "$DOTFILES/local/bin" -maxdepth 1 2>/dev/null)
info "installing to ~/.local/bin"
if [ ! -d "$HOME/.local/bin" ]; then
info "Creating ~/.local/bin"
mkdir -p "$HOME/.local/bin"
fi
for bin in $bin_files; do
target="$HOME/.local/bin/$(basename "$bin")"
if [ -e "$target" ]; then
info "~${target#$HOME} already exists... Skipping."
else
info "Creating symlink for $bin"
ln -s "$bin" "$target"
fi
done
}
setup_homebrew() {
title "Setting up Homebrew"
if test ! "$(command -v brew)"; then
info "Homebrew not installed. Installing."
# Run as a login shell (non-interactive) so that the script doesn't pause for user input
sudo apt-get install build-essential
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bashrc
success "Homebrew installed"
fi
# install brew dependencies from Brewfile
info "Installing brew dependencies from Brewfile"
brew bundle
success "brew dependencies installed"
# install fzf
echo -e
info "Installing fzf to the shell"
"$(brew --prefix)"/opt/fzf/install --key-bindings --completion --no-update-rc --no-fish
success "fzf installed to the shell"
info "Installing neovim plugins"
nvim --headless +PlugInstall +qa
success "neovim plugins installed"
info "Installing tmux plugin manager"
git clone --depth=1 https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
success "tmux plugin manager installed"
info "Installing tmux plugins"
~/.tmux/plugins/tpm/bin/install_plugins
success "tmux plugins installed"
}
function setup_terminfo() {
title "Configuring terminfo"
info "adding tmux.terminfo"
tic -x "$DOTFILES/resources/tmux.terminfo"
success "tmux.terminfo installed"
info "adding xterm-256color-italic.terminfo"
tic -x "$DOTFILES/resources/xterm-256color-italic.terminfo"
success "xterm-256color-italic.terminfo installed"
}
case "$1" in
backup)
backup
;;
link)
setup_symlinks
;;
homebrew)
setup_homebrew
;;
terminfo)
setup_terminfo
;;
all)
setup_symlinks
setup_terminfo
setup_homebrew
;;
*)
#echo -e $"\nUsage: $(basename "$0") {backup|link|git|homebrew|shell|terminfo|macos|all}\n"
setup_symlinks
setup_terminfo
setup_homebrew
;;
esac
echo -e
success "Done."