diff options
author | romkatv <roman.perepelitsa@gmail.com> | 2019-05-24 11:34:44 +0300 |
---|---|---|
committer | romkatv <roman.perepelitsa@gmail.com> | 2019-05-24 11:34:44 +0300 |
commit | bbebf516abeb55c96ad6e83478581b1230df6ec2 (patch) | |
tree | 65710561796992246c1a959a9f78446508f5ad4b | |
parent | 0acd14c92d4578f2014a1d72e1bb5a6994bd6976 (diff) |
show go_version when in a go module directory
-rwxr-xr-x | powerlevel9k.zsh-theme | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b7bcb39f..a34db566 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -944,8 +944,21 @@ prompt_go_version() { local -a match [[ $_P9K_RETVAL == (#b)*(go[[:digit:].]##)* ]] || return local v=$match[1] - local p=${GOPATH:-$(go env GOPATH 2>/dev/null)} - [[ -n $p && $PWD/ == $p/* ]] || return + local p=$GOPATH + if [[ -z $p ]]; then + if [[ -d $HOME/go ]]; then + p=$HOME/go + else + p=$(command go env GOPATH 2>/dev/null) && [[ -n $p ]] || return + fi + fi + if [[ $PWD/ != $p/* ]]; then + local dir=$PWD + while [[ ! -e $dir/go.mod ]]; do + [[ $dir == / ]] && return + dir=${dir:h} + done + fi "$1_prompt_segment" "$0" "$2" "green" "grey93" "GO_ICON" 0 '' "${v//\%/%%}" } |