Skip to content

Commit 4fb12c1

Browse files
committed
✨ New logging + update
add update feature and change logging
1 parent 0508d56 commit 4fb12c1

File tree

2 files changed

+87
-14
lines changed

2 files changed

+87
-14
lines changed

README.md

+28-12
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,76 @@
33
zsh plugin for installing and loading [tgenv](https://github.com/cunymatthieu/tgenv.git)
44
>Inpired by [zsh-pyenv](https://github.com/mattberther/zsh-pyenv)
55
6+
## Table of content
7+
8+
- [zsh-tgenv](#zsh-tgenv)
9+
- [Usage](#usage)
10+
- [Updating tgenv](#updating-tgenv)
11+
- [License](#license)
12+
613
## Usage
714

815
Once the plugin installed, `tgenv` will be available
916

10-
### Using [Antigen](https://github.com/zsh-users/antigen)
17+
- Using [Antigen](https://github.com/zsh-users/antigen)
1118

1219
Bundle `zsh-tgenv` in your `.zshrc`
1320

14-
```
21+
```shell
1522
antigen bundle ptavares/zsh-tgenv
1623
```
1724

18-
### Using [zplug](https://github.com/b4b4r07/zplug)
25+
- Using [zplug](https://github.com/b4b4r07/zplug)
1926

2027
Load `zsh-tgenv` as a plugin in your `.zshrc`
2128

22-
```
29+
```shell
2330
zplug "ptavares/zsh-tgenv"
2431
```
2532

26-
### Using [zgen](https://github.com/tarjoilija/zgen)
33+
- Using [zgen](https://github.com/tarjoilija/zgen)
2734

2835
Include the load command in your `.zshrc`
2936

30-
```
37+
```shell
3138
zget load ptavares/zsh-tgenv
3239
```
3340

34-
### As an [Oh My ZSH!](https://github.com/robbyrussell/oh-my-zsh) custom plugin
41+
- As an [Oh My ZSH!](https://github.com/robbyrussell/oh-my-zsh) custom plugin
3542

3643
Clone `zsh-tgenv` into your custom plugins repo and load as a plugin in your `.zshrc`
3744

3845
```shell
39-
git clone https://github.com/ptavares/zsh-tgenv ~/.oh-my-zsh/custom/plugins/zsh-tgenv
46+
git clone https://github.com/ptavares/zsh-tgenv.git ~/.oh-my-zsh/custom/plugins/zsh-tgenv
4047
```
4148

42-
```
49+
```shell
4350
plugins+=(zsh-tgenv)
4451
```
4552

4653
Keep in mind that plugins need to be added before `oh-my-zsh.sh` is sourced.
4754

48-
### Manually
55+
- Manually
4956

5057
Clone this repository somewhere (`~/.zsh-tgenv` for example) and source it in your `.zshrc`
5158

5259
```shell
5360
git clone https://github.com/ptavares/zsh-tgenv ~/.zsh-tgenv
5461
```
5562

63+
```shell
64+
source ~/.zsh-tgenv/zsh-tgenv.plugin.zsh
5665
```
57-
source ~/.zsh-tfenv/zsh-tfenv.plugin.zsh
66+
67+
## Updating tgenv
68+
69+
The plugin comes with a zsh function to update [tgenv](https://github.com/cunymatthieu/tgenv.git) manually
70+
71+
```shell
72+
# From zsh shell
73+
update_zsh_tgenv
5874
```
5975

60-
### License
76+
## License
6177

6278
[MIT](LICENCE)

zsh-tgenv.plugin.zsh

+59-2
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,78 @@
1+
#!/usr/bin/env zsh
2+
3+
#####################
4+
# COMMONS
5+
#####################
6+
autoload colors
7+
8+
#########################
9+
# CONSTANT
10+
#########################
11+
112
GITHUB="https://github.com"
13+
BOLD="bold"
14+
NONE="none"
15+
16+
#########################
17+
# PLUGIN MAIN
18+
#########################
219

320
[[ -z "$TGENV_HOME" ]] && export TGENV_HOME="$HOME/.tgenv"
421

22+
#########################
23+
# Functions
24+
#########################
25+
26+
_zsh_tgenv_log() {
27+
local font=$1
28+
local color=$2
29+
local msg=$3
30+
31+
if [ $font = $BOLD ]
32+
then
33+
echo $fg_bold[$color] "[zsh-tgenv-plugin] $msg" $reset_color
34+
else
35+
echo $fg[$color] "[zsh-tgenv-plugin] $msg" $reset_color
36+
fi
37+
}
38+
539
_zsh_tgenv_install() {
6-
echo "Installing tgenv..."
7-
git clone "${GITHUB}/cunymatthieu/tgenv.git" "${TGENV_HOME}"
40+
_zsh_tgenv_log $NONE "blue" "#################################"
41+
_zsh_tgenv_log $BOLD "blue" "Installing tgenv..."
42+
git clone "${GITHUB}/cunymatthieu/tgenv.git" "${TGENV_HOME}" >> /dev/null
43+
_zsh_tgenv_log $BOLD "green" "Install OK"
44+
_zsh_tgenv_log $NONE "blue" "#################################"
45+
}
46+
47+
update_zsh_tgenv() {
48+
_zsh_tgenv_log $NONE "blue" "#################################"
49+
_zsh_tgenv_log $BOLD "blue" "Updating tgenv..."
50+
51+
pushd "${TGENV_HOME}" > /dev/null
52+
if git pull --rebase --stat origin master
53+
then
54+
_zsh_tgenv_log $BOLD "green" "tgenv has been updated and/or is at the last version."
55+
popd > /dev/null
56+
else
57+
_zsh_tgenv_log $BOLD "red" "Error on updating. Please try again later."
58+
fi
59+
_zsh_tgenv_log $NONE "blue" "#################################"
60+
61+
unset _zsh_tgenv_log
862
}
963

1064
_zsh_tgenv_load() {
1165
# export PATH
1266
export PATH="$TGENV_HOME/bin:$PATH"
1367
}
1468

69+
1570
# install tgenv if it isnt already installed
1671
[[ ! -f "$TGENV_HOME/bin/tgenv" ]] && _zsh_tgenv_install
1772

1873
# load tgenv if it is installed
1974
if [[ -f "$TGENV_HOME/bin/tgenv" ]]; then
2075
_zsh_tgenv_load
2176
fi
77+
78+
unset -f _zsh_tgenv_install _zsh_tgenv_load

0 commit comments

Comments
 (0)