mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-25 13:30:07 +00:00
add nodenv prompt; #121
This commit is contained in:
parent
38da6a3c9b
commit
d75b714d8a
1 changed files with 51 additions and 0 deletions
|
@ -1530,6 +1530,57 @@ prompt_nodeenv() {
|
|||
fi
|
||||
}
|
||||
|
||||
function _p9k_read_nodenv_version_file() {
|
||||
[[ -r $1 ]] || return
|
||||
local rest
|
||||
read _P9K_RETVAL rest <$1 2>/dev/null
|
||||
[[ -n $_P9K_RETVAL ]]
|
||||
}
|
||||
|
||||
function _p9k_nodeenv_version_transform() {
|
||||
local dir=${NODENV_ROOT:-$HOME/.nodenv}/versions
|
||||
[[ -z $1 || $1 == system ]] && _P9K_RETVAL=$1 && return
|
||||
[[ -d $dir/$1 ]] && _P9K_RETVAL=$1 && return
|
||||
[[ -d $dir/${1/v} ]] && _P9K_RETVAL=${1/v} && return
|
||||
[[ -d $dir/${1#node-} ]] && _P9K_RETVAL=${1#node-} && return
|
||||
[[ -d $dir/${1#node-v} ]] && _P9K_RETVAL=${1#node-v} && return
|
||||
return 1
|
||||
}
|
||||
|
||||
function _p9k_nodenv_global_version() {
|
||||
_p9k_read_nodenv_version_file ${NODENV_ROOT:-$HOME/.nodenv}/version || _P9K_RETVAL=system
|
||||
}
|
||||
|
||||
################################################################
|
||||
# Segment to display nodenv information
|
||||
# https://github.com/nodenv/nodenv
|
||||
set_default POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW false
|
||||
prompt_nodenv() {
|
||||
_P9K_RETVAL=$NODENV_VERSION
|
||||
if [[ -z $_P9K_RETVAL ]]; then
|
||||
[[ $NODENV_DIR == /* ]] && local dir=$NODENV_DIR || local dir="$PWD/$NODENV_DIR"
|
||||
while [[ $dir != //[^/]# ]]; do
|
||||
_p9k_read_nodenv_version_file $dir/.node-version && break
|
||||
[[ $dir == / ]] && break
|
||||
dir=${dir:h}
|
||||
done
|
||||
if [[ -z $_P9K_RETVAL ]]; then
|
||||
[[ $POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW == true ]] || return
|
||||
_p9k_nodenv_global_version
|
||||
fi
|
||||
fi
|
||||
|
||||
_p9k_nodeenv_version_transform $_P9K_RETVAL || return
|
||||
local v=$_P9K_RETVAL
|
||||
|
||||
if [[ $POWERLEVEL9K_NODENV_PROMPT_ALWAYS_SHOW == false ]]; then
|
||||
_p9k_nodenv_global_version
|
||||
_p9k_nodeenv_version_transform $_P9K_RETVAL && [[ $v == $_P9K_RETVAL ]] && return
|
||||
fi
|
||||
|
||||
"$1_prompt_segment" "$0" "$2" "black" "green" 'NODE_ICON' 0 '' "${v//\%/%%}"
|
||||
}
|
||||
|
||||
################################################################
|
||||
# Segment to print a little OS icon
|
||||
prompt_os_icon() {
|
||||
|
|
Loading…
Reference in a new issue