add caching to prompt_dir

pull/78/head
romkatv 6 years ago
parent 97dbb6ab16
commit eff8d47b42

@ -856,49 +856,54 @@ prompt_dir() {
;; ;;
esac esac
local state='' icon='' [[ $POWERLEVEL9K_DIR_SHOW_WRITABLE == true && ! -w $PWD ]]
if [[ $POWERLEVEL9K_DIR_SHOW_WRITABLE == true && ! -w $PWD ]]; then local w=$?
state=NOT_WRITABLE if ! _p9k_cache_get $0 $w $fake_first "$delim" "${parts[@]}"; then
icon=LOCK_ICON local state='' icon=''
else if (( ! w )); then
case $PWD in state=NOT_WRITABLE
/etc|/etc/*) state=ETC; icon=ETC_ICON;; icon=LOCK_ICON
~) state=HOME; icon=HOME_ICON;; else
~/*) state=HOME_SUBFOLDER; icon=HOME_SUB_ICON;; case $PWD in
*) state=DEFAULT; icon=FOLDER_ICON;; /etc|/etc/*) state=ETC; icon=ETC_ICON;;
esac ~) state=HOME; icon=HOME_ICON;;
fi ~/*) state=HOME_SUBFOLDER; icon=HOME_SUB_ICON;;
*) state=DEFAULT; icon=FOLDER_ICON;;
esac
fi
local style=%b local style=%b
_p9k_color blue $0_$state BACKGROUND _p9k_color blue $0_$state BACKGROUND
_p9k_background $_P9K_RETVAL _p9k_background $_P9K_RETVAL
style+=$_P9K_RETVAL style+=$_P9K_RETVAL
_p9k_color "$DEFAULT_COLOR" "$0_$state" FOREGROUND _p9k_color "$DEFAULT_COLOR" "$0_$state" FOREGROUND
_p9k_foreground $_P9K_RETVAL _p9k_foreground $_P9K_RETVAL
style+=$_P9K_RETVAL style+=$_P9K_RETVAL
parts=("${(@)parts//\%/%%}") parts=("${(@)parts//\%/%%}")
[[ $fake_first == 0 && $parts[1] == '~' ]] && parts[1]=$POWERLEVEL9K_HOME_FOLDER_ABBREVIATION$style [[ $fake_first == 0 && $parts[1] == '~' ]] && parts[1]=$POWERLEVEL9K_HOME_FOLDER_ABBREVIATION$style
[[ $POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER == true && $#parts > 1 && -n $parts[2] ]] && parts[1]=() [[ $POWERLEVEL9K_DIR_OMIT_FIRST_CHARACTER == true && $#parts > 1 && -n $parts[2] ]] && parts[1]=()
local last_fg= local last_fg=
[[ $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD == true ]] && last_fg+=%B [[ $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD == true ]] && last_fg+=%B
if [[ -n $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND ]]; then if [[ -n $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND ]]; then
_p9k_translate_color $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND _p9k_translate_color $POWERLEVEL9K_DIR_PATH_HIGHLIGHT_FOREGROUND
_p9k_foreground $_P9K_RETVAL _p9k_foreground $_P9K_RETVAL
last_fg+=$_P9K_RETVAL last_fg+=$_P9K_RETVAL
fi fi
parts[-1]=$last_fg${parts[-1]//$'\0'/$'\0'$last_fg}$style parts[-1]=$last_fg${parts[-1]//$'\0'/$'\0'$last_fg}$style
parts=("${(@)parts//$'\0'/$delim$style}") parts=("${(@)parts//$'\0'/$delim$style}")
local sep=$POWERLEVEL9K_DIR_PATH_SEPARATOR$style local sep=$POWERLEVEL9K_DIR_PATH_SEPARATOR$style
if [[ -n $POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND ]]; then if [[ -n $POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND ]]; then
_p9k_translate_color $POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND _p9k_translate_color $POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND
_p9k_foreground $_P9K_RETVAL _p9k_foreground $_P9K_RETVAL
sep=$_P9K_RETVAL$sep sep=$_P9K_RETVAL$sep
fi fi
"$1_prompt_segment" "$0_$state" "$2" blue "$DEFAULT_COLOR" "$icon" 0 "" "${(pj.$sep.)parts}" _p9k_cache_set "$0_$state" "$2" blue "$DEFAULT_COLOR" "$icon" 0 "" "${(pj.$sep.)parts}"
fi
"$1_prompt_segment" "$_P9K_CACHE_VAL[@]"
} }
################################################################ ################################################################

Loading…
Cancel
Save