forked from zap-zsh/zap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.zsh
executable file
·56 lines (43 loc) · 1.6 KB
/
install.zsh
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
#!/usr/bin/env zsh
main() {
local BACKUP_SUFFIX="$(date +%Y-%m-%d)_$(date +%s)"
local ZAP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/zap"
local ZSHRC="${ZDOTDIR:-$HOME}/.zshrc"
# check if ZAP_DIR already exists
[[ -d "$ZAP_DIR" ]] && {
echo "Zap is already installed in '$ZAP_DIR'!"
read -q "res?Reinstall Zap? [y/N] "
echo ""
[[ $res == "n" ]] && {
echo "❕ skipped!"
return
}
echo "Reinstalling Zap..."
rm -rf "$ZAP_DIR"
}
# Get the branch of the Zap ZSH repository to clone
[[ $1 == "--branch" || $1 == "-b" && -n $2 ]] && local BRANCH="$2"
git clone --depth 1 -b "${BRANCH:-master}" https://github.com/zap-zsh/zap.git "$ZAP_DIR" > /dev/null 2>&1 || { echo "❌ Failed to install Zap" && return 2 }
# Check the .zshrc template exists
if [ ! -f "$ZAP_DIR/templates/default-zshrc" ]; then
echo "Template .zshrc file was not found in Zap installation"
return 2
fi
# Check if the current .zshrc file exists
if [ -f "$ZSHRC" ]; then
# Move the current .zshrc file to the new filename
mv "$ZSHRC" "${ZSHRC}_${BACKUP_SUFFIX}"
echo "Moved .zshrc to .zshrc_$BACKUP_SUFFIX"
else
echo "No .zshrc file found, creating a new one..."
touch "$ZSHRC"
fi
# Write out the .zshrc template to the .zshrc
cat "$ZAP_DIR/templates/default-zshrc" >> "$ZSHRC"
echo " Zapped"
echo "Find more plugins at http://zapzsh.org"
return 0
}
main $@
[[ $? -eq 0 ]] && source "${ZDOTDIR:-$HOME}/.zshrc" || return
# vim: ft=zsh ts=4 et