mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-01 05:16:05 +01:00
39797: obsolete the helper functions fixed by the previous two changes
Replacing them with the new ${var:P} modifier. Previous deltas may be useful for backport to zsh 5.2 and before.
This commit is contained in:
parent
4eed68e0bf
commit
4bc0d13911
2 changed files with 8 additions and 62 deletions
|
@ -10,6 +10,10 @@
|
|||
|
||||
2016-10-31 Barton E. Schaefer <schaefer@zsh.org>
|
||||
|
||||
* 39797: Completion/Unix/Type/_canonical_paths: obsolete the
|
||||
helper functions fixed by the previous two changes, replacing
|
||||
them with the new ${var:P} modifier.
|
||||
|
||||
* 39795: Completion/Unix/Type/_canonical_paths: preserve "cd -"
|
||||
behavior around directory shuffling in _canonical_paths_pwd
|
||||
|
||||
|
|
|
@ -7,59 +7,12 @@
|
|||
|
||||
# Usage: _canonical_paths [-A var] [-N] [-MJV12nfX] tag desc [paths...]
|
||||
|
||||
# -A, if specified, takes the paths from the array variable specified. Paths can
|
||||
# also be specified on the command line as shown above. -N, if specified,
|
||||
# -A, if specified, takes the paths from the array variable specified. Paths
|
||||
# can also be specified on the command line as shown above. -N, if specified,
|
||||
# prevents canonicalizing the paths given before using them for completion, in
|
||||
# case they are already so. `tag' and `desc' arguments are well, obvious :) In
|
||||
# addition, the options -M, -J, -V, -1, -2, -n, -F, -X are passed to compadd.
|
||||
|
||||
_canonical_paths_pwd() {
|
||||
# Get the canonical directory name by changing to it.
|
||||
integer chaselinks
|
||||
local oldpwd=$OLDPWD
|
||||
[[ -o chaselinks ]] && (( chaselinks = 1 ))
|
||||
setopt localoptions nopushdignoredups chaselinks noautopushd
|
||||
if builtin pushd -q -- $1 2>/dev/null; then
|
||||
REPLY=$PWD
|
||||
(( chaselinks )) || unsetopt chaselinks
|
||||
[[ -n $oldpwd && -d $oldpwd ]] && builtin cd -q $oldpwd # For "cd -"
|
||||
builtin popd -q
|
||||
else
|
||||
REPLY=$1
|
||||
fi
|
||||
}
|
||||
|
||||
_canonical_paths_get_canonical_path() {
|
||||
typeset newfile nondir
|
||||
typeset -A seen
|
||||
|
||||
REPLY=$1
|
||||
# Canonicalise the directory path. We may not be able to
|
||||
# do this if we can't read all components.
|
||||
if [[ -d $REPLY ]]; then
|
||||
_canonical_paths_pwd $REPLY
|
||||
else
|
||||
# Resolve any trailing symbolic links, guarding against loops.
|
||||
while [[ -z ${seen[$REPLY]} ]]; do
|
||||
seen[$REPLY]=1
|
||||
newfile=()
|
||||
zstat -A newfile +link $REPLY 2>/dev/null
|
||||
if [[ -n $newfile[1] ]]; then
|
||||
REPLY=$newfile[1]
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ $REPLY = */*[^/] && $REPLY != /[^/]# ]]; then
|
||||
# Don't try this if there's a trailing slash or we're in
|
||||
# the root directory.
|
||||
nondir=${REPLY##*/#}
|
||||
_canonical_paths_pwd ${REPLY%/#*}
|
||||
REPLY+="/$nondir"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_canonical_paths_add_paths () {
|
||||
# origpref = original prefix
|
||||
# expref = expanded prefix
|
||||
|
@ -71,15 +24,7 @@ _canonical_paths_add_paths () {
|
|||
expref=${~origpref} 2>/dev/null
|
||||
[[ $origpref == (|*/). ]] && rltrim=.
|
||||
curpref=${${expref%$rltrim}:-./}
|
||||
if [[ $expref:h == (.|..) ]]; then
|
||||
_canonical_paths_pwd $expref:h
|
||||
canpref=$REPLY/$expref:t
|
||||
elif zstat $curpref >&/dev/null; then
|
||||
_canonical_paths_get_canonical_path $curpref
|
||||
canpref=$REPLY
|
||||
else
|
||||
canpref=$curpref
|
||||
fi
|
||||
canpref=$curpref:P
|
||||
[[ $curpref == */ && $canpref == *[^/] ]] && canpref+=/
|
||||
canpref+=$rltrim
|
||||
[[ $expref == *[^/] && $canpref == */ ]] && origpref+=/
|
||||
|
@ -136,10 +81,7 @@ _canonical_paths() {
|
|||
if (( $__opts[(I)-N] )); then
|
||||
files=($@)
|
||||
else
|
||||
for __index in $@; do
|
||||
_canonical_paths_get_canonical_path $__index
|
||||
files+=($REPLY)
|
||||
done
|
||||
files+=($@:P)
|
||||
fi
|
||||
|
||||
local base=$PREFIX
|
||||
|
|
Loading…
Reference in a new issue