mirror of
https://github.com/rydesun/dotfiles.git
synced 2025-12-26 14:44:58 +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_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
|
||||
|
|
@ -24,26 +24,31 @@ Z_COLLAPSED_PWD_EXPAND_LAST=${Z_COLLAPSED_PWD_EXPAND_LAST:-1}
|
|||
for i in {$begin_index..$end_index}; do
|
||||
(( total_count <= Z_COLLAPSED_PWD_MAX_LENGTH )) && break
|
||||
|
||||
local name=${names[$i]}
|
||||
local first_c=${name:0:1}
|
||||
local full_name=${names[$i]}
|
||||
local first_c=${full_name:0:1}
|
||||
[[ $first_c == '.' ]] && offset=2 || offset=1
|
||||
local new_name=${name:0:$offset}
|
||||
(( ${#name} == ${#new_name} )) && continue
|
||||
local new_name=${full_name:0:$offset}
|
||||
(( ${#full_name} == ${#new_name} )) && continue
|
||||
names[$i]=$Z_PROMPT_COLLAPSED_PWD$new_name$Z_PROMPT_PWD_L
|
||||
|
||||
total_count=$(( total_count - ${#name:$offset} ))
|
||||
local last_collapsed=($i $name $offset)
|
||||
total_count=$(( total_count - ${#full_name:$offset} ))
|
||||
local last_collapsed=($i $full_name $offset)
|
||||
done
|
||||
|
||||
# 尽可能展开最后一个压缩的目录名
|
||||
if ((Z_COLLAPSED_PWD_EXPAND_LAST)) && [[ -n $last_collapsed ]]; then
|
||||
local expand_count=$(( Z_COLLAPSED_PWD_MAX_LENGTH - total_count ))
|
||||
if (( expand_count > 0 )); then
|
||||
local expanded_count=$(( expand_count + last_collapsed[3] ))
|
||||
local new_name=${${last_collapsed[2]}:0:$expanded_count}
|
||||
if [[ $Z_COLLAPSED_PWD_EXPAND_LAST = yes ]] && [[ -n $last_collapsed ]]; then
|
||||
local free_count=$(( Z_COLLAPSED_PWD_MAX_LENGTH - total_count ))
|
||||
if (( free_count > 0 )); then
|
||||
local visible_count=$(( free_count + last_collapsed[3] ))
|
||||
local full_name=$last_collapsed[2]
|
||||
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
|
||||
|
||||
local IFS="/"
|
||||
echo "${names[*]}"
|
||||
|
|
|
|||
2
.zshrc
2
.zshrc
|
|
@ -146,6 +146,8 @@ fi
|
|||
Z_COLLAPSED_PWD_RESERVE_COMPONENTS=1
|
||||
# 最大路径长度(非严格)
|
||||
Z_COLLAPSED_PWD_MAX_LENGTH=32
|
||||
# 当空间足够时,尽可能展开最后一个压缩的目录名
|
||||
#Z_COLLAPSED_PWD_EXPAND_LAST=yes
|
||||
autoload -Uz collapsed_pwd
|
||||
|
||||
precmd() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue