From 73a9ee7c870fcc93182c17f7d9d0c6942116169d Mon Sep 17 00:00:00 2001 From: Miroslav Šedivý <6774676+eumiro@users.noreply.github.com> Date: Fri, 11 Aug 2017 22:44:18 +0200 Subject: add TRUNCATE_TO_UNIQUE shortening dir strategy This creates the shortest unique path elements that can be unambiguously expanded to the original path. --- powerlevel9k.zsh-theme | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5bd5f586..3869d262 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -709,6 +709,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 + 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")" ;; -- cgit v1.2.3 From e464b4e2a559508f9f4e0a9bc28a3b1e7d08fbd6 Mon Sep 17 00:00:00 2001 From: Ben Hilburn Date: Sat, 12 Aug 2017 13:49:50 -0400 Subject: Adding reference for `truncate_to_unique` code. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3869d262..3baa50ce 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -711,7 +711,7 @@ prompt_dir() { ;; truncate_to_unique) # for each parent path component find the shortest unique beginning - # characters sequence + # characters sequence. Source: https://stackoverflow.com/a/45336078 paths=(${(s:/:)PWD}) cur_path='/' cur_short_path='/' -- cgit v1.2.3