aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristo Kotze <onaforeignshore@hotmail.co.uk>2018-02-10 13:23:27 +0300
committerChristo Kotze <onaforeignshore@hotmail.co.uk>2018-02-10 13:23:27 +0300
commit6d25e18779f33cd3339ecd491b3a195a714519ae (patch)
tree39464a893db9ba572237a5bcfdfecb6da71a154b
parent085a78b9b823ff1731070b229a9154bd4ade63b9 (diff)
Merged `truncate_to_unique` & state `NOT_WRITABLE`
Added `truncate_to_unique` and `NOT_WRITABLE` to @dritter's code.
-rwxr-xr-xpowerlevel9k.zsh-theme26
1 files changed, 25 insertions, 1 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 26936325..87b453a4 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -811,6 +811,27 @@ prompt_dir() {
# the current path.
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")"
;;
@@ -834,9 +855,12 @@ prompt_dir() {
"DEFAULT" "FOLDER_ICON"
"HOME" "HOME_ICON"
"HOME_SUBFOLDER" "HOME_SUB_ICON"
+ "NOT_WRITABLE" "LOCK_ICON"
)
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"
elif [[ $(print -P "%~") == '~'* ]]; then
current_state="HOME_SUBFOLDER"