-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
Β·278 lines (235 loc) Β· 8.87 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/bin/zsh
# dotbraga
#
# Usage:
# ./install [--all] Install everything
# ./install ohmyzsh Install only Oh My Zsh.
# Other values: dualboot, links, ViM, zsh-autosuggestions,
# zsh-syntax-highlighting, spaceship, powerlevel10k.
# Dotbraga global variable
# ------------------------------------------------------------------------------
export DOTBRAGA="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
VERSION=$(cat "${DOTBRAGA}/VERSION")
OHMYZSH_URL='https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh'
OHMYZSH_FOLDER="${HOME}/.oh-my-zsh"
POWERLEVEL10K_URL='https://github.com/romkatv/powerlevel10k'
POWERLEVEL10K_FOLDER="${OHMYZSH_FOLDER}/custom/themes/powerlevel10k"
SPACESHIP_PROMPT_URL='https://github.com/denysdovhan/spaceship-prompt'
SPACESHIP_PROMPT_FOLDER="${OHMYZSH_FOLDER}/custom/themes/spaceship-prompt"
ZSH_AUTOSUGGESTIONS_URL='https://github.com/zsh-users/zsh-autosuggestions'
ZSH_AUTOSUGGESTIONS_FOLDER="${OHMYZSH_FOLDER}/custom/plugins/zsh-autosuggestions"
ZSH_SYNTAX_HIGHLIGHTING_URL='https://github.com/zsh-users/zsh-syntax-highlighting'
ZSH_SYNTAX_HIGHLIGHTING_FOLDER="${OHMYZSH_FOLDER}/custom/plugins/zsh-syntax-highlighting"
source "${DOTBRAGA}/src/scripts/colors"
# dotbraga components
# ==============================================================================
install() {
# PUBLIC METHODS
# ============================================================================
# Install Oh My Zsh
# ----------------------------------------------------------------------------
ohmyzsh() {
setup 'Oh My Zsh' "${OHMYZSH_FOLDER}" ${OHMYZSH_URL}
}
# Install zsh-syntax-highlighting plugin for Oh My Zsh
# ----------------------------------------------------------------------------
zsh-syntax-highlighting() {
setup 'zsh-syntax-highlighting' "${ZSH_SYNTAX_HIGHLIGHTING_FOLDER}" ${ZSH_SYNTAX_HIGHLIGHTING_URL} true
}
# Install zsh-autosuggestions plugin for Oh My Zsh
# ----------------------------------------------------------------------------
zsh-autosuggestions() {
setup 'zsh-autosuggestions' "${ZSH_AUTOSUGGESTIONS_FOLDER}" ${ZSH_AUTOSUGGESTIONS_URL} true
}
# Install Spaceship theme for Oh My Zsh
# ----------------------------------------------------------------------------
spaceship() {
setup 'Spaceship zsh theme' "${SPACESHIP_PROMPT_FOLDER}" ${SPACESHIP_PROMPT_URL} true
ln -sfnv "${SPACESHIP_PROMPT_FOLDER}/spaceship.zsh-theme" "${OHMYZSH_FOLDER}/themes/spaceship.zsh-theme"
}
# Install Powerlevel10k theme for Oh My Zsh
# ----------------------------------------------------------------------------
powerlevel10k() {
setup 'Powerlevel10k' "${POWERLEVEL10K_FOLDER}" ${POWERLEVEL10K_URL} true
ln -sfnv "${POWERLEVEL10K_FOLDER}/powerlevel10k.zsh-theme" "${OHMYZSH_FOLDER}/themes/powerlevel10k.zsh-theme"
}
# Shortcut "Restart to Windows" for Dual Boot systems
# ----------------------------------------------------------------------------
dualboot() {
title "Shortcut 'Restart to Windows' for Dual Boot systems"
for EXTENSION in desktop png sh; do
sudo ln -sfnv "${DOTBRAGA}/src/dualboot/windows.${EXTENSION}" /usr/share/applications
done
success "β
'Restart to Windows' created successfuly."
}
# Symlink src/bin scripts to /usr/bin
# ----------------------------------------------------------------------------
bin() {
step 'π Link some scripts to /usr/bin...'
find "${DOTBRAGA}/src/bin" -type f,l -exec sudo ln -sfnv -t /usr/bin {} \;
}
# Create symlinks
# ----------------------------------------------------------------------------
links() {
setopt NULL_GLOB
title 'Create symlinks for dotfiles' && cp -afrsv ${DOTBRAGA}/src/dotfiles/{.,}* ${HOME}
# title 'Copy files to /etc' && sudo cp -afrv ${DOTBRAGA}/src/etc/{.,}* /etc
title 'Create symlinks for /usr/bin' && sudo cp -afrsv ${DOTBRAGA}/src/bin/{.,}* /usr/bin
echo && success 'β
Links created!'
}
# Install VIM - Vi IMproved with settings
# ----------------------------------------------------------------------------
ViM() {
VIM_FILE="${HOME}/.vimrc"
VIM_FOLDER="${HOME}/.vim"
COMPILE=false
title 'Install VIM - Vi IMproved with settings'
step 'π Check if VIM is installed...'
[[ ! $(command -v vim) ]] && step 'π» Installing vim...' || step 'πΎ Updating vim...'
if ! ${COMPILE}; then
sudo apt install -y vim
else
# Install dependencies
sudo apt install -y \
clang \
libpython3-dev \
libtool-bin \
libxt-dev \
make
# Get Vim latest version
VIM_DIST=${DOTBRAGA}/dist/vim
if [[ ! -d ${VIM_DIST} ]]; then
git clone --depth=1 https://github.com/vim/vim "${VIM_DIST}"
cd "${VIM_DIST}" || exit
else
cd "${VIM_DIST}" || exit
git pull origin master
fi
# Enable Python 3 interpreter
sed -i '/^#CONF_OPT_PYTHON3 = --enable-python3interp$/s/^#//g' src/Makefile
# Install Vim
make >/dev/null && sudo make install >/dev/null
# Undo src/Makefile changes
git checkout src/Makefile
fi
step 'π» Installing vim plugins and settings...'
ln -sfnv "${DOTBRAGA}"/src/vim/.vimrc "${VIM_FILE}"
ln -sfnv "${DOTBRAGA}"/src/vim "${VIM_FOLDER}"
vim -E -s -u "${VIM_FILE}" +PlugInstall +qall >/dev/null
success 'β
VIM installed and configured'
}
# Call the install script without parameters or passing -a / --all parameter
# ----------------------------------------------------------------------------
all() {
ohmyzsh
spaceship
powerlevel10k
zsh-syntax-highlighting
zsh-autosuggestions
dualboot
bin
links
ViM
echo
info 'Finished'
}
# PRIVATE METHODS
# ============================================================================
# Abstract method to install or update components.
# ----------------------------------------------------------------------------
setup() {
NAME=$1
INSTALL_FOLDER=$2
INSTALL_URL=$3
CLONE=$4
title "Install ${NAME}"
step 'π Check if installed...'
if [[ -d "${INSTALL_FOLDER}" ]]; then
step 'πΎ Updating...'
update "${INSTALL_FOLDER}"
else
step 'π» Installing...'
if [[ ${CLONE} == 'true' ]]; then
git clone "${INSTALL_URL}" "${INSTALL_FOLDER}"
else
sh -c "$(curl -fsSL "${INSTALL_URL}")"
fi
fi
# TODO: Check error code
success "β
${NAME} install finished."
}
# Print header.
# ----------------------------------------------------------------------------
header() {
printf "${BWhite}%s${ColorOff} ${Yellow}%s${ColorOff}\n" 'dotbraga' "${VERSION}"
}
# Define title of each internal function.
# ----------------------------------------------------------------------------
title() {
printf "\n${BPurple}%s${ColorOff}\n" "${1}"
}
# Print steps information about installation.
# ----------------------------------------------------------------------------
step() {
printf "${ColorOff}%s\n" "${1}"
}
# Asks the user a question and captures the answer.
# ----------------------------------------------------------------------------
ask() {
printf '%s' "${Yellow}" &&
read -r "ANSWER?${1} ${2} " &&
printf '%s' "${ColorOff}"
return "${ANSWER}"
}
# Inform user about some action.
# ----------------------------------------------------------------------------
info() {
printf "${Blue}"'info'"${ColorOff} %s\n" "${1}"
}
# Debug some information.
# ----------------------------------------------------------------------------
debug() {
printf "${IYellow}"'debug'"${ColorOff} %s\n" "${*}"
}
# Print done message
# ----------------------------------------------------------------------------
success() {
printf "${Green}success${ColorOff} %s\n" "${1}"
}
# Abort execution with message
# ----------------------------------------------------------------------------
abort() {
printf "${Red}abort${ColorOff} %s\n" "${1}"
}
# Update plugin or theme using git pull
# ----------------------------------------------------------------------------
update() {
{
cd "${1}" && git pull || exit
}
}
# FUNCTION CALL
# ============================================================================
header
args=("$@")
# If empty ARGS, run everything...
[[ "${args[*]}" == '' ]] && all
# ...or detect the function to run.
for arg in "${args[@]}"; do
case $arg in
bin) bin ;;
dualboot) dualboot ;;
ohmyzsh) ohmyzsh ;;
powerlevel10k) powerlevel10k ;;
spaceship) spaceship ;;
vim) ViM ;;
zsh-autosuggestions | autosuggestions) zsh-autosuggestions ;;
zsh-syntax-highlighting | syntax-highlighting) zsh-syntax-highlighting ;;
-l | --link | links) links "$@" ;;
"" | -a | --all | all) all ;;
*) exit ;;
esac
done
}
# Call the script
install "$@"