1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-09-25 04:30:46 +00:00

speed up rbenv prompt

This commit is contained in:
romkatv 2019-05-22 18:07:09 +02:00
parent 89d7caa16b
commit 3e3da88dbc

View file

@ -1301,20 +1301,47 @@ prompt_ram() {
"$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" 'RAM_ICON' 0 '' "$(printSizeHumanReadable "$ramfree" $base)" "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" 'RAM_ICON' 0 '' "$(printSizeHumanReadable "$ramfree" $base)"
} }
function _p9k_read_rbenv_version_file() {
[[ -r $1 ]] || return
local content
read -r content <$1 2>/dev/null
_P9K_RETVAL="${${(A)=content}[1]}"
[[ -n $_P9K_RETVAL ]]
}
function _p9k_rbenv_global_version() {
_p9k_read_rbenv_version_file ${RBENV_ROOT:-$HOME/.rbenv}/version || _P9K_RETVAL=system
}
################################################################ ################################################################
# Segment to display rbenv information # Segment to display rbenv information
# https://github.com/rbenv/rbenv#choosing-the-ruby-version # https://github.com/rbenv/rbenv#choosing-the-ruby-version
set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false set_default POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW false
prompt_rbenv() { prompt_rbenv() {
if [[ -n "$RBENV_VERSION" ]]; then local v=$RBENV_VERSION
"$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" 'RUBY_ICON' 0 '' "$RBENV_VERSION" if [[ -z $v ]]; then
elif [ $commands[rbenv] ]; then [[ $RBENV_DIR == /* ]] && local dir=$RBENV_DIR || local dir="$PWD/$RBENV_DIR"
local rbenv_version_name="$(rbenv version-name)" while true; do
local rbenv_global="$(rbenv global)" if _p9k_read_rbenv_version_file $dir/.ruby-version; then
if [[ "${rbenv_version_name}" != "${rbenv_global}" || "${POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW}" == "true" ]]; then v=$_P9K_RETVAL
"$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" 'RUBY_ICON' 0 '' "${rbenv_version_name//\%/%%}" break
fi fi
if [[ $dir == / ]]; then
[[ $POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW == true ]] || return
_p9k_rbenv_global_version
v=$_P9K_RETVAL
break
fi
dir=${dir:h}
done
fi fi
if [[ $POWERLEVEL9K_RBENV_PROMPT_ALWAYS_SHOW == false ]]; then
_p9k_rbenv_global_version
[[ $v == $_P9K_RETVAL ]] && return
fi
"$1_prompt_segment" "$0" "$2" "red" "$DEFAULT_COLOR" 'RUBY_ICON' 0 '' "${v//\%/%%}"
} }
################################################################ ################################################################