Skip to content

Commit

Permalink
install go version from go.mod
Browse files Browse the repository at this point in the history
Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
  • Loading branch information
ivankatliarchuk committed Sep 2, 2023
1 parent dab1f89 commit f20a095
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
10 changes: 5 additions & 5 deletions shell/aliase/kube
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ command -v kubens > /dev/null && alias ks=kubens # https://github.com/a
command -v kubedecode > /dev/null && alias kd=kubedecode # https://github.com/mveritym/kubedecode
command -v kubectx > /dev/null && alias kx=kubectx # https://github.com/ahmetb/kubectx

if ! kubectl config current-context >/dev/null 2>&1; then
: # do nothing as not inside context
else
: # do nothing as we may switch to context an there is no need to realod
fi
# if ! kubectl config current-context >/dev/null 2>&1; then
# : # do nothing as not inside context
# else
# : # do nothing as we may switch to context an there is no need to realod
# fi

## Health
alias k.h='kubectl get cs'
Expand Down
2 changes: 1 addition & 1 deletion vendor/dotbot
6 changes: 3 additions & 3 deletions zsh/functions/eval.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ fi
source <(navi widget zsh)
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

if [ $commands[kubectl] ]; then
source <(kubectl completion zsh)
fi
# if [ $commands[kubectl] ]; then
# source <(kubectl completion zsh)
# fi

if [ $commands[kubectx] ]; then
kubectx --unset >/dev/null 2>&1
Expand Down
35 changes: 25 additions & 10 deletions zsh/functions/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,33 @@ load-nvmrc
# Automatically switch and load golang versions when a directory has an `.gvmrc` file
load-gvmrc() {
if exists gvm; then
if [ -f .gvmrc ]; then
if ! go version | grep "$(cat .gvmrc)" >/dev/null 2>&1; then
gvm use $(cat .gvmrc) >/dev/null 2>&1
echo "Switched golang to version \"$(go version)\""
if [ -f .gvmrc ] || [ -f go.mod ]; then
local GO_VERSION=$(go version | { read _ _ v _; echo ${v#go}; })
if [ -f .gvmrc ]; then
local GO_GVMRC_VERSION=$(cat .gvmrc)
if ! go version | grep "$GO_GVMRC_VERSION" >/dev/null 2>&1; then
gvm use $GO_GVMRC_VERSION >/dev/null 2>&1
fi
if [ $? -eq 1 ]
then
gvm install $GO_GVMRC_VERSION
gvm use $GO_GVMRC_VERSION >/dev/null 2>&1
fi
fi
if [ -f go.mod ]; then
local GO_LOCAL_VERSION=$(go list -f {{.GoVersion}} -m)
if [[ "$GO_VERSION" == "$GO_LOCAL_VERSION" ]]; then
# echo "version match"
else
gvm use ${GO_LOCAL_VERSION} 2>&1
fi
if [ $? -eq 1 ]
then
gvm install go${GO_LOCAL_VERSION}
gvm use ${GO_LOCAL_VERSION} 2>&1
fi
fi
if [ $? -eq 1 ]
then
gvm install $(cat .gvmrc)
gvm use $(cat .gvmrc) >/dev/null 2>&1
echo "Switched golang to version \"$(go version)\""
fi
fi
fi
}
add-zsh-hook chpwd load-gvmrc
Expand Down

0 comments on commit f20a095

Please sign in to comment.