1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-04 06:14:50 +01:00
zsh/Functions/Zftp/zfautocheck

42 lines
1.3 KiB
Text
Raw Normal View History

1999-04-25 17:43:45 +02:00
# function zfautocheck {
# This function is used to implement auto-open behaviour.
#
# With first argument including n, don't change to the old directory; else do.
#
# Set do_close to 1 if the connection was not previously open, 0 otherwise
# With first argument including d, don't set do_close to 1. Broadly
1999-04-25 17:43:45 +02:00
# speaking, we use this mechanism to shut the connection after use
# if the connection had been explicitly closed (i.e. didn't time out,
# which zftp test investigates) and we are not using a directory
# command, which implies we are looking for something so should stay open
# for it.
2007-07-03 09:13:29 +02:00
# Remember the old location: will be overwritten by
1999-04-25 17:43:45 +02:00
# a successful open.
2007-07-03 09:13:29 +02:00
local lastloc=$zfconfig[lastloc_$ZFTP_SESSION]
# Don't print out user messages when re-opening the connection.
local ZFTP_VERBOSE=${ZFTP_VERBOSE//0}
# Unset the delay counter from the progress meter in case there was an
# abnormal exit.
(( ${+zftpseconds} )) && unset zftpseconds
1999-04-25 17:43:45 +02:00
if [[ -z $ZFTP_HOST ]]; then
zfopen || return 1
2007-07-03 09:13:29 +02:00
[[ $1 == *d* ]] || do_close=1
1999-04-25 17:43:45 +02:00
elif zftp test 2>/dev/null; then
return 0
else
zfopen || return 1
fi
2007-07-03 09:13:29 +02:00
if [[ $1 == *n* ]]; then
1999-04-25 17:43:45 +02:00
return 0
2007-07-03 09:13:29 +02:00
elif [[ -n $lastloc && $ZFTP_HOST == ${lastloc%%:*} ]]; then
# don't print directory since we're just going back where we were.
zfcd ${lastloc#*:} >& /dev/null
1999-04-25 17:43:45 +02:00
fi
# }