Tôi đoán bạn có thể thêm các thành phần của $PWDvào cddanh sách hoàn thành, mặc dù điều này dường như đòi hỏi không quan trọng với _cd; đó là, một phiên bản tùy chỉnh _cdphải xuất hiện đầu tiên trong $fpath.
% cd && mkdir zcomp
% cp $fpath[-1]/_cd zcomp
% fpath=(~/zcomp $fapth)
Sau đó lên trên cùng của ~/zcomp/_cdmột chức năng
_our_pwd() {
  _values ourpwd ${(ps:/:)PWD}
}
và sau đó ngay trước _alternativedòng thêm những gì trả về danh sách thay thế
  ...
  alt=("$service-options:$service option:_cd_options" "$alt[@]")
fi
alt=(ourpwd:pwd:_our_pwd "$alt[@]")
_alternative "$alt[@]" && ret=0
return ret
...
mặc dù điều này sẽ luôn thêm các pwdthành phần để cdhoàn thành:
% cd
Users    jdoe    Applications/  Desktop/  Documents/  Downloads/  Library/
...
với logic bổ sung, bạn chỉ có thể thêm các $PWDthành phần khi đã có đối số thứ hai thay vì luôn luôn.
Tuy nhiên! Điều này luôn làm rối tung việc cdhoàn thành và yêu cầu chúng tôi phải vá lỗi _cdhoàn thành ngược dòng . Một tùy chọn khác là tạo một tên mới cho hàm được cung cấp bởi hai-arg cd, có lẽ được gọi cdsubvà chỉ có các thành PWDphần hoàn thành xuất hiện cho điều đó. Thêm cái này vào~/.zshrc
function cdsub { builtin cd "$@" }
Và sau đó, một sự _cd hoàn thành_cdsub ruột được đặt ở đâu đó trong $fpath:
#compdef cdsub
#
# Modified version of _cd from ZSH 5.3.1 with specific support for the
# `cd old new` form whereby PWD elements are provided for completion.
_cd_options() {
  _arguments -s \
  '-q[quiet, no output or use of hooks]' \
  '-s[refuse to use paths with symlinks]' \
  '(-P)-L[retain symbolic links ignoring CHASE_LINKS]' \
  '(-L)-P[resolve symbolic links as CHASE_LINKS]'
}
setopt localoptions nonomatch
local expl ret=1 curarg
integer argstart=2 noopts
if (( CURRENT > 1 )); then
  # if not in command position, may have options.
  # Careful: -<-> is not an option.
  while [[ $words[$argstart] = -* && argstart -lt CURRENT ]]; do
    curarg=$words[$argstart]
    [[ $curarg = -<-> ]] && break
    (( argstart++ ))
    [[ $curarg = -- ]] && noopts=1 && break
  done
fi
if [[ CURRENT -eq $((argstart+1)) ]]; then
  # cd old new: look for old in $PWD and see what can replace it
  local rep
  # Get possible completions using word in position 2
  rep=(${~PWD/$words[$argstart]/*}~$PWD(-/))
  # Now remove all the common parts of $PWD and the completions from this
  rep=(${${rep#${PWD%%$words[$argstart]*}}%${PWD#*$words[$argstart]}})
  (( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep
else
  _values ourpwd ${(ps:/:)PWD} && ret=0
  return ret
fi
               
              
cd p also <Tab>, hoặccd p also <left arrow x 5> <Tab>?