mirror of
https://github.com/rydesun/dotfiles.git
synced 2026-07-16 22:16:11 +08:00
Fix zsh expanded collapsed_pwd
This commit is contained in:
parent
a2bbf8ee77
commit
ce2fd26263
2 changed files with 20 additions and 13 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
Z_COLLAPSED_PWD_RESERVE_COMPONENTS=${Z_COLLAPSED_PWD_RESERVE_COMPONENTS:-1}
|
Z_COLLAPSED_PWD_RESERVE_COMPONENTS=${Z_COLLAPSED_PWD_RESERVE_COMPONENTS:-1}
|
||||||
Z_COLLAPSED_PWD_MAX_LENGTH=${Z_COLLAPSED_PWD_MAX_LENGTH:-32}
|
Z_COLLAPSED_PWD_MAX_LENGTH=${Z_COLLAPSED_PWD_MAX_LENGTH:-32}
|
||||||
Z_COLLAPSED_PWD_EXPAND_LAST=${Z_COLLAPSED_PWD_EXPAND_LAST:-1}
|
Z_COLLAPSED_PWD_EXPAND_LAST=${Z_COLLAPSED_PWD_EXPAND_LAST:-no}
|
||||||
|
|
||||||
() {
|
() {
|
||||||
[[ $# == 0 ]] && local pwd="$PWD" || local pwd=$1
|
[[ $# == 0 ]] && local pwd="$PWD" || local pwd=$1
|
||||||
|
|
@ -24,24 +24,29 @@ Z_COLLAPSED_PWD_EXPAND_LAST=${Z_COLLAPSED_PWD_EXPAND_LAST:-1}
|
||||||
for i in {$begin_index..$end_index}; do
|
for i in {$begin_index..$end_index}; do
|
||||||
(( total_count <= Z_COLLAPSED_PWD_MAX_LENGTH )) && break
|
(( total_count <= Z_COLLAPSED_PWD_MAX_LENGTH )) && break
|
||||||
|
|
||||||
local name=${names[$i]}
|
local full_name=${names[$i]}
|
||||||
local first_c=${name:0:1}
|
local first_c=${full_name:0:1}
|
||||||
[[ $first_c == '.' ]] && offset=2 || offset=1
|
[[ $first_c == '.' ]] && offset=2 || offset=1
|
||||||
local new_name=${name:0:$offset}
|
local new_name=${full_name:0:$offset}
|
||||||
(( ${#name} == ${#new_name} )) && continue
|
(( ${#full_name} == ${#new_name} )) && continue
|
||||||
names[$i]=$Z_PROMPT_COLLAPSED_PWD$new_name$Z_PROMPT_PWD_L
|
names[$i]=$Z_PROMPT_COLLAPSED_PWD$new_name$Z_PROMPT_PWD_L
|
||||||
|
|
||||||
total_count=$(( total_count - ${#name:$offset} ))
|
total_count=$(( total_count - ${#full_name:$offset} ))
|
||||||
local last_collapsed=($i $name $offset)
|
local last_collapsed=($i $full_name $offset)
|
||||||
done
|
done
|
||||||
|
|
||||||
# 尽可能展开最后一个压缩的目录名
|
# 尽可能展开最后一个压缩的目录名
|
||||||
if ((Z_COLLAPSED_PWD_EXPAND_LAST)) && [[ -n $last_collapsed ]]; then
|
if [[ $Z_COLLAPSED_PWD_EXPAND_LAST = yes ]] && [[ -n $last_collapsed ]]; then
|
||||||
local expand_count=$(( Z_COLLAPSED_PWD_MAX_LENGTH - total_count ))
|
local free_count=$(( Z_COLLAPSED_PWD_MAX_LENGTH - total_count ))
|
||||||
if (( expand_count > 0 )); then
|
if (( free_count > 0 )); then
|
||||||
local expanded_count=$(( expand_count + last_collapsed[3] ))
|
local visible_count=$(( free_count + last_collapsed[3] ))
|
||||||
local new_name=${${last_collapsed[2]}:0:$expanded_count}
|
local full_name=$last_collapsed[2]
|
||||||
names[$last_collapsed[1]]=$Z_PROMPT_COLLAPSED_PWD$new_name$Z_PROMPT_PWD_L
|
local new_name=${full_name:0:$visible_count}
|
||||||
|
if [[ ${#new_name} == ${#full_name} ]]; then
|
||||||
|
names[$last_collapsed[1]]=$new_name
|
||||||
|
else
|
||||||
|
names[$last_collapsed[1]]=$Z_PROMPT_COLLAPSED_PWD$new_name$Z_PROMPT_PWD_L
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
2
.zshrc
2
.zshrc
|
|
@ -146,6 +146,8 @@ fi
|
||||||
Z_COLLAPSED_PWD_RESERVE_COMPONENTS=1
|
Z_COLLAPSED_PWD_RESERVE_COMPONENTS=1
|
||||||
# 最大路径长度(非严格)
|
# 最大路径长度(非严格)
|
||||||
Z_COLLAPSED_PWD_MAX_LENGTH=32
|
Z_COLLAPSED_PWD_MAX_LENGTH=32
|
||||||
|
# 当空间足够时,尽可能展开最后一个压缩的目录名
|
||||||
|
#Z_COLLAPSED_PWD_EXPAND_LAST=yes
|
||||||
autoload -Uz collapsed_pwd
|
autoload -Uz collapsed_pwd
|
||||||
|
|
||||||
precmd() {
|
precmd() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue