aboutsummaryrefslogtreecommitdiff
path: root/internal/p10k.zsh
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2019-07-17 00:49:55 +0300
committerromkatv <roman.perepelitsa@gmail.com>2019-07-17 00:49:55 +0300
commit1acc559cc22fc4774a1d3baf35cfc305d7513df9 (patch)
treec9687c601c277ff59c102410d636af5bd22bc47d /internal/p10k.zsh
parent1ed5c3f17767c10be45b393ab2e66fda6bc6f9c4 (diff)
parent3bf893162065cabe604241daba0ba9781122af7d (diff)
Merge branch 'master' into dev
Diffstat (limited to 'internal/p10k.zsh')
-rwxr-xr-xinternal/p10k.zsh54
1 files changed, 54 insertions, 0 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh
index 7180e2d0..b22a5f07 100755
--- a/internal/p10k.zsh
+++ b/internal/p10k.zsh
@@ -1504,6 +1504,58 @@ 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() {
+ (( $+commands[nodenv] )) || return
+ _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() {
@@ -1566,6 +1618,7 @@ function _p9k_rbenv_global_version() {
# https://github.com/rbenv/rbenv#choosing-the-ruby-version
set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false
prompt_rbenv() {
+ (( $+commands[rbenv] )) || return
local v=$RBENV_VERSION
if [[ -z $v ]]; then
[[ $RBENV_DIR == /* ]] && local dir=$RBENV_DIR || local dir="$PWD/$RBENV_DIR"
@@ -2297,6 +2350,7 @@ function _p9k_pyenv_global_version() {
# https://github.com/pyenv/pyenv#choosing-the-python-version
set_default POWERLEVEL9K_PYENV_PROMPT_ALWAYS_SHOW false
prompt_pyenv() {
+ (( $+commands[pyenv] )) || return
local v=${(j.:.)${(@)${(s.:.)PYENV_VERSION}#python-}}
if [[ -z $v ]]; then
[[ $PYENV_DIR == /* ]] && local dir=$PYENV_DIR || local dir="$PWD/$PYENV_DIR"