aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorBen Hilburn <bhilburn@gmail.com>2017-08-12 20:52:10 +0300
committerGitHub <noreply@github.com>2017-08-12 20:52:10 +0300
commit9f4faf7f21a992f32114f134dfb0737657241b37 (patch)
tree1e8de4a7dcb38e93c4d02ebd16aff4c4eea4d5da /powerlevel9k.zsh-theme
parent02332d596214c8e68bd3e86a8d0b90d3a4d60cf1 (diff)
parente464b4e2a559508f9f4e0a9bc28a3b1e7d08fbd6 (diff)
Merge pull request #596 from eumiro/truncate_to_unique
Add TRUNCATE_TO_UNIQUE shortening dir strategy
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme21
1 files changed, 21 insertions, 0 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index a4469406..3c34f0bb 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -780,6 +780,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")"
;;