Merged `truncate_to_unique` & state `NOT_WRITABLE`

Added `truncate_to_unique` and `NOT_WRITABLE` to @dritter's code.
pull/22/head
Christo Kotze 7 years ago
parent 085a78b9b8
commit 6d25e18779

@ -811,6 +811,27 @@ prompt_dir() {
# the current path. # the current path.
current_path=$current_path${PWD#${last_marked_folder}*} current_path=$current_path${PWD#${last_marked_folder}*}
;; ;;
truncate_to_unique)
# for each parent path component find the shortest unique beginning
# characters sequence. Source: https://stackoverflow.com/a/45336078
paths=(${(s:/:)PWD})
cur_path='/'
cur_short_path='/'
for directory in ${paths[@]}
do
cur_dir=''
for (( i=0; i<${#directory}; i++ )); do
cur_dir+="${directory:$i:1}"
matching=("$cur_path"/"$cur_dir"*/)
if [[ ${#matching[@]} -eq 1 ]]; then
break
fi
done
cur_short_path+="$cur_dir/"
cur_path+="$directory/"
done
current_path="${cur_short_path: : -1}"
;;
*) *)
current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")" current_path="$(print -P "%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c")"
;; ;;
@ -834,9 +855,12 @@ prompt_dir() {
"DEFAULT" "FOLDER_ICON" "DEFAULT" "FOLDER_ICON"
"HOME" "HOME_ICON" "HOME" "HOME_ICON"
"HOME_SUBFOLDER" "HOME_SUB_ICON" "HOME_SUBFOLDER" "HOME_SUB_ICON"
"NOT_WRITABLE" "LOCK_ICON"
) )
local current_state="DEFAULT" local current_state="DEFAULT"
if [[ $(print -P "%~") == '~' ]]; then if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then
current_state="NOT_WRITABLE"
elif [[ $(print -P "%~") == '~' ]]; then
current_state="HOME" current_state="HOME"
elif [[ $(print -P "%~") == '~'* ]]; then elif [[ $(print -P "%~") == '~'* ]]; then
current_state="HOME_SUBFOLDER" current_state="HOME_SUBFOLDER"

Loading…
Cancel
Save