summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpowerlevel9k.zsh-theme46
1 files changed, 29 insertions, 17 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index e2259897..73573a07 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -745,6 +745,31 @@ prompt_command_execution_time() {
}
################################################################
+# Determine the unique path - this is needed for the
+# truncate_to_unique strategy.
+#
+function getUniqueFolder() {
+ local trunc_path directory test_dir test_dir_length
+ local -a matching
+ local -a paths
+ local cur_path='/'
+ paths=(${(s:/:)1})
+ for directory in ${paths[@]}; do
+ test_dir=''
+ for (( i=0; i < ${#directory}; i++ )); do
+ test_dir+="${directory:$i:1}"
+ matching=("$cur_path"/"$test_dir"*/)
+ if [[ ${#matching[@]} -eq 1 ]]; then
+ break
+ fi
+ done
+ trunc_path+="$test_dir/"
+ cur_path+="$directory/"
+ done
+ echo "${trunc_path: : -1}"
+}
+
+################################################################
# Dir: current working directory
# Parameters:
# * $1 Alignment: string - left|right
@@ -811,23 +836,10 @@ prompt_dir() {
# for each parent path component find the shortest unique beginning
# characters sequence. Source: https://stackoverflow.com/a/45336078
if (( ${#current_path} > 1 )); then # root and home are exceptions and won't have paths
- local matching
- local cur_path='/'
- [[ $current_path != "~"* ]] && trunc_path='/' || trunc_path=''
- for directory in ${paths[@]}; do
- test_dir=''
- for (( i=0; i<${#directory}; i++ )); do
- test_dir+="${directory:$i:1}"
- matching=("$cur_path"/"$test_dir"*/)
- if [[ ${#matching[@]} -eq 1 ]]; then
- break
- fi
- done
- trunc_path+="$test_dir/"
- cur_path+="$directory/"
- done
- [[ $current_path == "~"* ]] && trunc_path="~/$trunc_path"
- current_path="${trunc_path: : -1}"
+ # cheating here to retain ~ as home folder
+ local home_path="$(getUniqueFolder $HOME)"
+ trunc_path="$(getUniqueFolder $PWD)"
+ [[ $current_path == "~"* ]] && current_path="~${trunc_path//${home_path}/}" || current_path="/${trunc_path}"
fi
;;
truncate_with_folder_marker)