function fill-line() { emulate -L zsh local left_len=$(prompt-length $1) local right_len=$(prompt-length $2 9999) local pad_len=$((COLUMNS - left_len - right_len - ${ZLE_RPROMPT_INDENT:-1})) if (( pad_len < 1 )); then # Not enough space for the right part. Drop it. echo -E - ${1} else local pad=${(pl.$pad_len.. .)} # pad_len spaces echo -E - ${1}${pad}${2} fi }
而這之中又引用了一個 prompt-length 函數
function prompt-length() { emulate -L zsh local COLUMNS=${2:-$COLUMNS} local -i x y=$#1 m if (( y )); then while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do x=y (( y *= 2 )); done local xy while (( y > x + 1 )); do m=$(( x + (y - x) / 2 )) typeset ${${(%):-$1%$m(l.x.y)}[-1]}=$m done fi echo $x }
## 選單補全,用 tab 移動選擇 zstyle ':completion:*' menu select
#setopt completealiases
# Load version control information autoload -Uz vcs_info precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable zstyle ':vcs_info:git:*' formats ' %F{1}%b%f'
# Set up the prompt (with git branch name) setopt PROMPT_SUBST
# 靠右上的提示 # 因為要自己計算剩下的長度還可以怎麼用才可以對齊右邊 function prompt-length() { emulate -L zsh local COLUMNS=${2:-$COLUMNS} local -i x y=$#1 m if (( y )); then while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do x=y (( y *= 2 )); done local xy while (( y > x + 1 )); do m=$(( x + (y - x) / 2 )) typeset ${${(%):-$1%$m(l.x.y)}[-1]}=$m done fi echo $x } # 所以滿一行中間要空白 function fill-line() { emulate -L zsh local left_len=$(prompt-length $1) local right_len=$(prompt-length $2 9999) local pad_len=$((COLUMNS - left_len - right_len - ${ZLE_RPROMPT_INDENT:-1})) if (( pad_len < 1 )); then # Not enough space for the right part. Drop it. echo -E - ${1} else local pad=${(pl.$pad_len.. .)} # pad_len spaces echo -E - ${1}${pad}${2} fi }