mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-09-22 20:01:31 +02:00
24775: improve _cd option handling
This commit is contained in:
parent
0db1d3f839
commit
594f783c77
@ -1,5 +1,8 @@
|
||||
2008-03-28 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* 24775: Completion/Zsh/Command/_cd, Doc/Zsh/compsys.yo: improve
|
||||
option handling.
|
||||
|
||||
* users/12739: configure.ac: multiple arguments to --with-term-lib
|
||||
weren't handled properly.
|
||||
|
||||
|
@ -11,17 +11,37 @@
|
||||
# it's not a lot of use. If you don't type the + or - it will
|
||||
# complete directories as normal.
|
||||
|
||||
_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
|
||||
local expl ret=1 curarg
|
||||
integer argstart=2 noopts
|
||||
|
||||
if [[ CURRENT -eq 3 ]]; then
|
||||
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[2]/*}~$PWD(-/))
|
||||
rep=(${~PWD/$words[$argstart]/*}~$PWD(-/))
|
||||
# Now remove all the common parts of $PWD and the completions from this
|
||||
rep=(${${rep#${PWD%%$words[2]*}}%${PWD#*$words[2]}})
|
||||
rep=(${${rep#${PWD%%$words[$argstart]*}}%${PWD#*$words[$argstart]}})
|
||||
(( $#rep )) && _wanted -C replacement strings expl replacement compadd -a rep
|
||||
else
|
||||
# Complete directory stack entries with ~ or when not in command position
|
||||
@ -70,6 +90,11 @@ else
|
||||
[[ CURRENT -ne 1 || ( -z "$path[(r).]" && $PREFIX != */* ) ]] &&
|
||||
alt=( "${cdpath+local-}directories:${cdpath+local }directory:_path_files -/" "$alt[@]" )
|
||||
|
||||
if [[ CURRENT -eq argstart && noopts -eq 0 && $PREFIX = -* ]] &&
|
||||
zstyle -t ":completion:${curcontext}:options" complete-options; then
|
||||
alt=("$service-options:$service option:_cd_options" "$alt[@]")
|
||||
fi
|
||||
|
||||
_alternative "$alt[@]" && ret=0
|
||||
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user