-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzsh-sdkman.plugin.zsh
executable file
·134 lines (110 loc) · 3.87 KB
/
zsh-sdkman.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
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
#!/usr/bin/env zsh
#####################
# COMMONS
#####################
autoload colors
#########################
# CONSTANT
#########################
BOLD="bold"
NONE="none"
#########################
# PLUGIN MAIN
#########################
[[ -z "$SDKMAN_DIR" ]] && export SDKMAN_DIR="$HOME/.sdkman"
ZSH_SDKMAN_VERSION_FILE=${SDKMAN_DIR}/version.txt
#########################
# Functions
#########################
_zsh_sdkman_log() {
local font=$1
local color=$2
local msg=$3
if [ $font = $BOLD ]
then
echo $fg_bold[$color] "[zsh-sdkman-plugin] $msg" $reset_color
else
echo $fg[$color] "[zsh-sdkman-plugin] $msg" $reset_color
fi
}
_zsh_sdkman_check_requirement() {
local command=$1
_zsh_sdkman_log $NONE "blue" "#############################################"
_zsh_sdkman_log $NONE "blue" "Looking for ${command}..."
which "${command}" > /dev/null 2>&1
if [[ $? -eq 1 ]]; then
_zsh_sdkman_log $NONE "blue" "Not found"
_zsh_sdkman_log $NONE "blue" "========================================="
_zsh_sdkman_log $NONE "blue" "Please install ${command} on your system"
_zsh_sdkman_log $NONE "blue" "using your favourite package manager."
_zsh_sdkman_log $NONE "blue" "========================================="
exit 1
fi
}
_zsh_sdkman_check_requirement_list() {
_zsh_sdkman_check_requirement zip
_zsh_sdkman_check_requirement unzip
_zsh_sdkman_check_requirement curl
}
_zsh_sdkman_last_version() {
echo $(curl -s https://get.sdkman.io/ | grep SDKMAN_VERSION | head -n 1 | cut -d '"' -f 2)
}
_zsh_sdkman_install() {
_zsh_sdkman_log $NONE "blue" "#############################################"
_zsh_sdkman_log $BOLD "blue" "Installing sdkman..."
_zsh_sdkman_check_requirement_list
local last_version=$(_zsh_sdkman_last_version)
_zsh_sdkman_log $NONE "blue" "-> retrieve last version of sdkman..."
_zsh_sdkman_log $NONE "blue" " -> download and install sdkman ${last_version}"
curl -s "https://get.sdkman.io" | bash > /dev/null 2>&1
echo ${last_version} > ${ZSH_SDKMAN_VERSION_FILE}
_zsh_sdkman_log $BOLD "green" "Install OK"
_zsh_sdkman_log $NONE "blue" "#############################################"
}
update_zsh_sdkman() {
_zsh_sdkman_log $NONE "blue" "#############################################"
_zsh_sdkman_log $BOLD "blue" "Checking new version of sdkman..."
local current_version=$(cat ${ZSH_SDKMAN_VERSION_FILE})
local last_version=$(_zsh_sdkman_last_version)
if is-at-least ${last_version//+/.} ${current_version}
then
_zsh_sdkman_log $BOLD "green" "Already up to date, current version : ${current_version}"
else
_zsh_sdkman_log $NONE "blue" "-> Updating sdkman..."
sdk selfupdate force > /dev/null 2>&1
echo ${version} > ${ZSH_SDKMAN_VERSION_FILE}
_zsh_sdkman_log $BOLD "green" "Update OK"
fi
_zsh_sdkman_log $NONE "blue" "#############################################"
}
_zsh_sdkman_load() {
source "$HOME/.sdkman/bin/sdkman-init.sh"
# # export PATH
# export PATH=${PATH}:${SDKMAN_DIR}
}
# install sdkman if it isnt already installed
[[ ! -f "${ZSH_SDKMAN_VERSION_FILE}" ]] &&_zsh_sdkman_install
# load sdkman if it is installed
if [[ -f "${ZSH_SDKMAN_VERSION_FILE}" ]]; then
_zsh_sdkman_load
# Rebuild completion
0=${(%):-%N}
fpath=(${0:A:h} $fpath)
autoload -U compinit && compinit -C
fi
########################################################
##### ALIASES
########################################################
alias sdki='sdk install'
alias sdkun='sdk uninstall'
alias sdkls='sdk list'
alias sdku='sdk use'
alias sdkd='sdk default'
alias sdkc='sdk current'
alias sdkup='sdk upgrade'
alias sdkv='sdk version'
alias sdkb='sdk broadcast'
alias sdko='sdk offline'
alias sdksu='sdk selfupdate'
alias sdkf='sdk flush'
unset -f _zsh_sdkman_install _zsh_sdkman_check_requirement_list _zsh_sdkman_check_requirement _zsh_sdkman_load