-
Notifications
You must be signed in to change notification settings - Fork 1
/
zsh-tgenv.plugin.zsh
executable file
·82 lines (65 loc) · 1.94 KB
/
zsh-tgenv.plugin.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
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
#!/usr/bin/env zsh
#####################
# COMMONS
#####################
autoload colors
#########################
# CONSTANT
#########################
GITHUB="https://github.com"
BOLD="bold"
NONE="none"
#########################
# PLUGIN MAIN
#########################
[[ -z "$TGENV_HOME" ]] && export TGENV_HOME="$HOME/.tgenv"
#########################
# Functions
#########################
_zsh_tgenv_log() {
local font=$1
local color=$2
local msg=$3
if [ $font = $BOLD ]
then
echo $fg_bold[$color] "[zsh-tgenv-plugin] $msg" $reset_color
else
echo $fg[$color] "[zsh-tgenv-plugin] $msg" $reset_color
fi
}
_zsh_tgenv_install() {
_zsh_tgenv_log $NONE "blue" "#################################"
_zsh_tgenv_log $BOLD "blue" "Installing tgenv..."
git clone "${GITHUB}/tgenv/tgenv.git" "${TGENV_HOME}" >> /dev/null
_zsh_tgenv_log $BOLD "green" "Install OK"
_zsh_tgenv_log $NONE "blue" "#################################"
}
update_zsh_tgenv() {
_zsh_tgenv_log $NONE "blue" "#################################"
_zsh_tgenv_log $BOLD "blue" "Updating tgenv..."
pushd "${TGENV_HOME}" > /dev/null
if git pull --rebase --stat origin main
then
_zsh_tgenv_log $BOLD "green" "tgenv has been updated and/or is at the last version."
popd > /dev/null
else
_zsh_tgenv_log $BOLD "red" "Error on updating. Please try again later."
fi
_zsh_tgenv_log $NONE "blue" "#################################"
unset _zsh_tgenv_log
}
_zsh_tgenv_load() {
# export PATH if needed
local -r plugin_dir="$TGENV_HOME/bin:$PATH"
# Add the plugin bin directory path if it doesn't exist in $PATH.
if [[ -z ${path[(r)$plugin_dir]} ]]; then
path+=($plugin_dir)
fi
}
# install tgenv if it isnt already installed
[[ ! -f "$TGENV_HOME/bin/tgenv" ]] && _zsh_tgenv_install
# load tgenv if it is installed
if [[ -f "$TGENV_HOME/bin/tgenv" ]]; then
_zsh_tgenv_load
fi
unset -f _zsh_tgenv_install _zsh_tgenv_load