about summary refs log tree commit diff
path: root/Functions/Zftp/zfgoto
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Zftp/zfgoto')
-rw-r--r--Functions/Zftp/zfgoto31
1 files changed, 11 insertions, 20 deletions
diff --git a/Functions/Zftp/zfgoto b/Functions/Zftp/zfgoto
index bd1cdbfe5..57651e383 100644
--- a/Functions/Zftp/zfgoto
+++ b/Functions/Zftp/zfgoto
@@ -2,6 +2,9 @@
 # Go to bookmark bname, a location on a remote FTP host.  Unless
 # this was the last session or is for anonymous FTP, prompt for
 # the user's password.
+#
+# Maybe this should try and look for an appropriate session to use
+# for the transfer.
 
 emulate -L zsh
 setopt extendedglob
@@ -11,33 +14,20 @@ setopt extendedglob
 : ${ZFTP_BMFILE:=${ZFDOTDIR:-$HOME}/.zfbkmarks}
 
 typeset -A bkmarks
-local line ncftp opt optlist
+local line opt_n opt
 
-while [[ $1 == -* ]]; do
-  if [[ $1 == - || $1 == -- ]]; then
-    shift;
-    break;
-  fi
-  optlist=${1#-}
-  for (( i = 1; i <= $#optlist; i++)); do
-    opt=$optlist[$i]
-    case $opt in
-      n) ncftp=1
-	 ;;
-      *) print option $opt not recognised >&2
-	 return 1
-	 ;;
-    esac
-  done
-  shift
+while getopts :n opt; do
+  [[ $opt = '?' ]] && print "zfgoto: bad option: -$OPTARG" && return 1
+  eval "opt_$opt=1"
 done
+(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
 
 if (( $# != 1 )); then
   print "Usage: zfgoto bookmark" >&2
   return 1
 fi
 
-if [[ -n $ncftp && -f ~/.ncftp/bookmarks ]]; then
+if [[ -n $opt_n && -f ~/.ncftp/bookmarks ]]; then
   local oldifs=$IFS
   IFS=,
   while read -rA line; do
@@ -73,7 +63,8 @@ if [[ $ZFTP_USER = $user && $ZFTP_HOST = $host ]]; then
 elif [[ $user = ftp || $user = anonymous ]]; then
   # Anonymous ftp, so we don't need password etc.
   zfanon $host && [[ -n $dir ]] && zfcd $dir
-elif [[ $zflastsession = ${host}:* && $user = $zflastuser ]]; then
+elif [[ $zfconfig[lastloc_$ZFTP_SESSION] = ${host}:* &&
+  $user = $zfconfig[lastuser_$ZFTP_SESSION] ]]; then
   # This was the last session, so assume it's still setup in the
   # open parameters
   zfopen && [[ -n $dir ]] && zfcd $dir