আমি তোমাদের উপাদান যোগ করতে পারিনি অনুমান $PWDকরতে cdএই সঙ্গে তুচ্ছ প্রয়োজন মনে হচ্ছে যদিও সমাপ্তির তালিকা, _cd; যে একটি কাস্টমাইজড সংস্করণ _cdপ্রথম প্রদর্শিত হবে $fpath।
% cd && mkdir zcomp
% cp $fpath[-1]/_cd zcomp
% fpath=(~/zcomp $fapth)
তারপরে উপরে ~/zcomp/_cdএকটি ফাংশন যুক্ত করুন
_our_pwd() {
_values ourpwd ${(ps:/:)PWD}
}
এবং তারপরে _alternativeলাইনের ঠিক আগে যুক্ত করে কী বিকল্পগুলির তালিকায় ফিরে আসে
...
alt=("$service-options:$service option:_cd_options" "$alt[@]")
fi
alt=(ourpwd:pwd:_our_pwd "$alt[@]")
_alternative "$alt[@]" && ret=0
return ret
...
যদিও সব সময় যোগ হবে pwdথেকে উপাদান cdসম্পূর্ণকরণ:
% cd
Users jdoe Applications/ Desktop/ Documents/ Downloads/ Library/
...
অতিরিক্ত যুক্তি দিয়ে আপনি কেবল তখন $PWDউপাদানগুলি যুক্ত করতে পারেন যখন ইতিমধ্যে সর্বদা পরিবর্তে ইতিমধ্যে দ্বিতীয় যুক্তি উপস্থিত থাকে।
যাহোক! এটি সর্বদা সম্পূর্ণরূপে ব্যর্থ হয় cdএবং আমাদের প্রবাহের _cdসমাপ্তি বন্ধকে প্যাচ করে । আরেকটি বিকল্প হ'ল দ্বি-আর্গ দ্বারা সরবরাহিত ফাংশনটির জন্য একটি নতুন নাম তৈরি করা cd, সম্ভবত বলা হয় cdsubএবং কেবলমাত্র PWDউপাদানগুলির সমাপ্তির জন্য এটি উপস্থিত হয়। এটিতে যুক্ত করুন~/.zshrc
function cdsub { builtin cd "$@" }
এবং তারপরে কোথাও _cd রাখার_cdsub জন্য একটি অভ্যাসপূর্ণ সমাপ্তি$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>বাcd p also <left arrow x 5> <Tab>?