-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·190 lines (161 loc) · 4.85 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env bash
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 [ -e "$filename" ] && [ ! -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
}
init_git_submodule() {
cd "$DOTFILES"
git submodule update --init
}
setup_git() {
title "Setting up Git"
defaultName=$(git config user.name)
defaultEmail=$(git config user.email)
defaultGithub=$(git config github.user)
read -rp "Name [$defaultName] " name
read -rp "Email [$defaultEmail] " email
read -rp "Github username [$defaultGithub] " github
git config -f ~/.gitconfig-local user.name "${name:-$defaultName}"
git config -f ~/.gitconfig-local user.email "${email:-$defaultEmail}"
git config -f ~/.gitconfig-local github.user "${github:-$defaultGithub}"
init_git_submodule
}
setup_shell() {
title "Configuring shell"
[[ -n "$(command -v brew)" ]] && zsh_path="$(brew --prefix)/bin/zsh" || zsh_path="$(which zsh)"
if ! grep "$zsh_path" /etc/shells; then
info "adding $zsh_path to /etc/shells"
echo "$zsh_path" | sudo tee -a /etc/shells
fi
if [[ "$SHELL" != "$zsh_path" ]]; then
chsh -s "$zsh_path"
info "default shell changed to $zsh_path"
fi
# install oh-my-zsh with syntax highlighting, autosuggestions
if [[ "$SHELL" != "$zsh_path" ]] && [[ ! -d "$HOME/.oh-my-zsh" ]]; then
export KEEP_ZSHRC='yes'
export RUNZSH='no'
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # from oh-my-zsh github
export ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
zsh -c 'git clone https://github.com/zsh-users/zsh-autosuggestions.git "$ZSH_CUSTOM/plugins/zsh-autosuggestions"'
zsh -c 'git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"'
fi
}
case "$1" in
backup)
backup
;;
link)
case "$2" in
bash)
default=$(grep -v '^#' $DOTFILES/bash/defaults)
echo $default
;;
ssh)
;;
tmux)
;;
vim)
;;
all)
;;
*)
echo -e $"\nUsage: $(basename "$0") link <bash|ssh|tmux|vim|[all]>\n"
exit 1
;;
esac
;;
git)
setup_git
;;
shell)
setup_shell
;;
all)
setup_symlinks
setup_shell
init_git_submodule
setup_git
;;
*)
echo -e $"\nUsage: $(basename "$0") {backup|link|shell|git|all}\n"
exit 1
;;
esac
echo -e
success "Done."