mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-06 06:51:33 +01:00
100 lines
2.8 KiB
Text
100 lines
2.8 KiB
Text
|
# function zfdir {
|
||
|
# Long directory of remote server.
|
||
|
# The remote directory is cached. In fact, two caches are kept:
|
||
|
# one of the standard listing of the current directory, i.e. zfdir
|
||
|
# with no arguments, and another for everything else.
|
||
|
# To access the appropriate cache, just use zfdir with the same
|
||
|
# arguments as previously. zfdir -r will also re-use the `everything
|
||
|
# else' cache; you can always reuse the current directory cache just
|
||
|
# with zfdir on its own.
|
||
|
#
|
||
|
# The current directory cache is emptied when the directory changes;
|
||
|
# the other is kept until a new zfdir with a non-empty argument list.
|
||
|
# Both are removed when the connection is closed.
|
||
|
#
|
||
|
# zfdir -f will force the existing cache to be ignored, e.g. if you know
|
||
|
# or suspect the directory has changed.
|
||
|
# zfdir -d will remove both caches without listing anything.
|
||
|
# If you need to pass -r, -f or -d to the dir itself, use zfdir -- -d etc.;
|
||
|
# unrecognised options are passed through to dir, but zfdir options must
|
||
|
# appear first and unmixed with the others.
|
||
|
|
||
|
emulate -L zsh
|
||
|
setopt extendedglob
|
||
|
|
||
|
local file opt optlist redir i newargs force
|
||
|
|
||
|
while [[ $1 = -* ]]; do
|
||
|
if [[ $1 = - || $1 = -- ]]; then
|
||
|
shift;
|
||
|
break;
|
||
|
elif [[ $1 != -[rfd]## ]]; then
|
||
|
# pass options through to ls
|
||
|
break;
|
||
|
fi
|
||
|
optlist=${1#-}
|
||
|
for (( i = 1; i <= $#optlist; i++)); do
|
||
|
opt=$optlist[$i]
|
||
|
case $optlist[$i] in
|
||
|
r) redir=1
|
||
|
;;
|
||
|
f) force=1
|
||
|
;;
|
||
|
d) [[ -n $zfcurdir && -f $zfcurdir ]] && rm -f $zfcurdir
|
||
|
[[ -n $zfotherdir && -f $zfotherdir ]] && rm -f $zfotherdir
|
||
|
zftp_fcache=()
|
||
|
return 0
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
shift
|
||
|
done
|
||
|
|
||
|
zfautocheck -d
|
||
|
|
||
|
# directory hack, see zfcd
|
||
|
for (( i = 1; i <= $#argv; i++ )); do
|
||
|
if [[ $argv[$i] = $HOME || $argv[$i] = $HOME/* ]]; then
|
||
|
argv[$i]="~${argv[$i]#$HOME}"
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
if [[ $# -eq 0 ]]; then
|
||
|
# Cache it in the current directory file. This means that repeated
|
||
|
# calls to zfdir with no arguments always use a cached file.
|
||
|
[[ -z $zfcurdir ]] && zfcurdir=${TMPPREFIX}zfcurdir$$
|
||
|
file=$zfcurdir
|
||
|
else
|
||
|
# Last directly looked at was not the current one, or at least
|
||
|
# had non-standard arguments.
|
||
|
[[ -z $zfotherdir ]] && zfotherdir=${TMPPREFIX}zfotherdir$$
|
||
|
file=$zfotherdir
|
||
|
newargs="$*"
|
||
|
if [[ -f $file && $redir != 1 && $force -ne 1 ]]; then
|
||
|
# Don't use the cached file if the arguments changed.
|
||
|
[[ $newargs = $zfotherargs ]] || rm -f $file
|
||
|
fi
|
||
|
zfotherargs=$newargs
|
||
|
fi
|
||
|
|
||
|
if [[ $force -eq 1 ]]; then
|
||
|
rm -f $file
|
||
|
# if it looks like current directory has changed, better invalidate
|
||
|
# the filename cache, too.
|
||
|
(( $# == 0 )) && zftp_fcache=()
|
||
|
fi
|
||
|
|
||
|
if [[ -n $file && -f $file ]]; then
|
||
|
eval ${PAGER:-more} \$file
|
||
|
else
|
||
|
if (zftp test); then
|
||
|
# Works OK in subshells
|
||
|
zftp dir $* | tee $file | eval ${PAGER-:more}
|
||
|
else
|
||
|
# Doesn't work in subshells (IRIX 6.2 --- why?)
|
||
|
zftp dir $* >$file
|
||
|
eval ${PAGER-:more} $file
|
||
|
fi
|
||
|
fi
|
||
|
# }
|