From 6dfd92f8c1d60892ea9b2a57e93cd22a8cb75c2a Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Sat, 18 Jul 2020 10:43:49 +0200 Subject: [PATCH] allow optional offset in POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER; see #896 --- config/p10k-classic.zsh | 5 +++++ config/p10k-lean-8colors.zsh | 5 +++++ config/p10k-lean.zsh | 5 +++++ config/p10k-rainbow.zsh | 5 +++++ internal/p10k.zsh | 13 ++++++------- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/config/p10k-classic.zsh b/config/p10k-classic.zsh index 6379158b..76638267 100644 --- a/config/p10k-classic.zsh +++ b/config/p10k-classic.zsh @@ -247,6 +247,11 @@ # /foo/bar/git_repo/nested_git_repo/baz, prompt will display git_repo/nested_git_repo/baz (first) # or nested_git_repo/baz (last). This assumes that git_repo and nested_git_repo contain markers # and other directories don't. + # + # Optionally, "first" and "last" can be followed by ":" where is an integer. + # This moves the truncation point to the right (positive offset) or to the left (negative offset) + # relative to the marker. Plain "first" and "last" are equivalent to "first:0" and "last:0" + # respectively. typeset -g POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER=false # Don't shorten this many last directory segments. They are anchors. typeset -g POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 diff --git a/config/p10k-lean-8colors.zsh b/config/p10k-lean-8colors.zsh index c9a09bde..d5e97604 100644 --- a/config/p10k-lean-8colors.zsh +++ b/config/p10k-lean-8colors.zsh @@ -241,6 +241,11 @@ # /foo/bar/git_repo/nested_git_repo/baz, prompt will display git_repo/nested_git_repo/baz (first) # or nested_git_repo/baz (last). This assumes that git_repo and nested_git_repo contain markers # and other directories don't. + # + # Optionally, "first" and "last" can be followed by ":" where is an integer. + # This moves the truncation point to the right (positive offset) or to the left (negative offset) + # relative to the marker. Plain "first" and "last" are equivalent to "first:0" and "last:0" + # respectively. typeset -g POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER=false # Don't shorten this many last directory segments. They are anchors. typeset -g POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index f874a584..68fb3ec3 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -241,6 +241,11 @@ # /foo/bar/git_repo/nested_git_repo/baz, prompt will display git_repo/nested_git_repo/baz (first) # or nested_git_repo/baz (last). This assumes that git_repo and nested_git_repo contain markers # and other directories don't. + # + # Optionally, "first" and "last" can be followed by ":" where is an integer. + # This moves the truncation point to the right (positive offset) or to the left (negative offset) + # relative to the marker. Plain "first" and "last" are equivalent to "first:0" and "last:0" + # respectively. typeset -g POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER=false # Don't shorten this many last directory segments. They are anchors. typeset -g POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 diff --git a/config/p10k-rainbow.zsh b/config/p10k-rainbow.zsh index 74db332c..7deeb594 100644 --- a/config/p10k-rainbow.zsh +++ b/config/p10k-rainbow.zsh @@ -247,6 +247,11 @@ # /foo/bar/git_repo/nested_git_repo/baz, prompt will display git_repo/nested_git_repo/baz (first) # or nested_git_repo/baz (last). This assumes that git_repo and nested_git_repo contain markers # and other directories don't. + # + # Optionally, "first" and "last" can be followed by ":" where is an integer. + # This moves the truncation point to the right (positive offset) or to the left (negative offset) + # relative to the marker. Plain "first" and "last" are equivalent to "first:0" and "last:0" + # respectively. typeset -g POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER=false # Don't shorten this many last directory segments. They are anchors. typeset -g POWERLEVEL9K_SHORTEN_DIR_LENGTH=1 diff --git a/internal/p10k.zsh b/internal/p10k.zsh index ab8b1c61..b11f3ffe 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -1847,10 +1847,10 @@ prompt_dir() { done if [[ -n $_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER ]]; then local _2=$'\2' - if [[ $_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER == last ]]; then - (( e = ${parts[(I)*$_2]} )) + if [[ $_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER == last* ]]; then + (( e = ${parts[(I)*$_2]} + ${_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER#*:} )) else - (( e = ${parts[(ib:2:)*$_2]} )) + (( e = ${parts[(ib:2:)*$_2]} + ${_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER#*:} )) fi if (( e > 1 && e <= $#parts )); then parts[1,e-1]=() @@ -6980,9 +6980,8 @@ _p9k_init_params() { _p9k_declare -e POWERLEVEL9K_SHORTEN_DELIMITER _p9k_declare -s POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER '' case $_POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER in - first) ;; - last) ;; - true) _POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER=last;; + first|last) _POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER+=:0;; + (first|last):(|-)<->);; *) _POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER=;; esac [[ -z $_POWERLEVEL9K_SHORTEN_FOLDER_MARKER ]] && _POWERLEVEL9K_DIR_TRUNCATE_BEFORE_MARKER= @@ -7742,7 +7741,7 @@ _p9k_must_init() { [[ $sig == $_p9k__param_sig ]] && return 1 _p9k_deinit fi - _p9k__param_pat=$'v100\1'${(q)ZSH_VERSION}$'\1'${(q)ZSH_PATCHLEVEL}$'\1' + _p9k__param_pat=$'v101\1'${(q)ZSH_VERSION}$'\1'${(q)ZSH_PATCHLEVEL}$'\1' _p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\1' _p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1' _p9k__param_pat+=$'$GITSTATUS_CACHE_DIR\1$GITSTATUS_AUTO_INSTALL\1${ZLE_RPROMPT_INDENT:-1}\1'