mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-11-01 18:30:55 +01:00
24768: add -q option to cd, chdir, pushd, popd
use in _canonical_paths add 4.3.6 release note with this and other stuff
This commit is contained in:
parent
42ddb45fe8
commit
50d9cdeae4
5 changed files with 93 additions and 46 deletions
|
|
@ -15,42 +15,45 @@
|
|||
|
||||
_canonical_paths_pwd() {
|
||||
# Get the canonical directory name by changing to it.
|
||||
# To be run in a subshell.
|
||||
(( ${+functions[chpwd]} )) && unfunction chpwd
|
||||
setopt CHASE_LINKS
|
||||
cd $1 2>/dev/null && pwd
|
||||
integer chaselinks
|
||||
[[ -o chaselinks ]] && (( chaselinks = 1 ))
|
||||
setopt localoptions nopushdignoredups chaselinks
|
||||
if builtin pushd -q -- $1 2>/dev/null; then
|
||||
REPLY=$PWD
|
||||
(( chaselinks )) || unsetopt chaselinks
|
||||
builtin popd -q
|
||||
else
|
||||
REPLY=$1
|
||||
fi
|
||||
}
|
||||
|
||||
_canonical_paths_get_canonical_path() {
|
||||
typeset newfile dir
|
||||
typeset newfile nondir
|
||||
typeset -A seen
|
||||
|
||||
REPLY=$1
|
||||
# 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
|
||||
|
||||
# Canonicalise the directory path. We may not be able to
|
||||
# do this if we can't read all components.
|
||||
if [[ -d $REPLY ]]; then
|
||||
dir="$(_canonical_paths_pwd $REPLY)"
|
||||
if [[ -n $dir ]]; then
|
||||
REPLY=$dir
|
||||
fi
|
||||
elif [[ $REPLY = */*[^/] && $REPLY != /[^/]# ]]; then
|
||||
# Don't try this if there's a trailing slash or we're in
|
||||
# the root directory.
|
||||
dir="$(_canonical_paths_pwd ${REPLY%/*})"
|
||||
if [[ -n $dir ]]; then
|
||||
REPLY=$dir/${REPLY##*/}
|
||||
_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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue