summaryrefslogtreecommitdiff
path: root/Completion/Builtins/_zftp
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Builtins/_zftp')
-rw-r--r--Completion/Builtins/_zftp100
1 files changed, 71 insertions, 29 deletions
diff --git a/Completion/Builtins/_zftp b/Completion/Builtins/_zftp
index 9be9c94db..0d6530dfc 100644
--- a/Completion/Builtins/_zftp
+++ b/Completion/Builtins/_zftp
@@ -1,50 +1,92 @@
-#defpatcomp zf*
-
-# Don't try any more completion after this.
-_compskip=1
+#compdef -p zf*
# Completion for zftp builtin and zf* functions. The functions
-# zfcd_match and zfget_match (used for old-style completion)
+# zfcd_match and zfget_match (also used for old-style completion)
# need to be installed for remote file and directory completion to work.
-local subcom
+# emulate -L zsh
+
+# Don't try any more completion after this.
+_compskip=all
+
+local subcom expl curcontext="${curcontext}"
-if [[ $COMMAND = zftp ]]; then
- if [[ $CURRENT -eq 1 ]]; then
- compadd -m open params user login type ascii binary mode put \
- putat get getat append appendat ls dir local remote mkdir rmdir
+if [[ $words[1] = zftp ]]; then
+ if [[ $CURRENT -eq 2 ]]; then
+ _wanted commands expl sub-command \
+ compadd open params user login type ascii binary mode put \
+ putat get getat append appendat ls dir local remote mkdir rmdir \
+ session rmsession
return
fi
- subcom=$1
+ subcom=$words[2]
+ curcontext="${curcontext/:zftp:/:zftp-${words[2]}:}"
else
- subcom=$COMMAND
+ subcom=$words[1]
fi
case $subcom in
*(cd|ls|dir))
- # complete remote directories; we could be smarter about hiding prefixes
- zfcd_match $PREFIX $SUFFIX
- (( $#reply )) && compadd -m -S/ -q $reply
- ;;
+ # complete remote directories
+ _wanted directories && zfcd_match $PREFIX $SUFFIX
+ ;;
*(get(|at)|gcp|delete|remote))
- # complete remote files
- zfget_match $PREFIX $SUFFIX
- (( $#reply )) && compadd -F fignore -m $reply
- ;;
+ # complete remote files
+ _wanted files && zfget_match $PREFIX $SUFFIX
+ ;;
*(put(|at)|pcp))
- # complete local files
- _files
- ;;
+ # complete local files
+ _wanted files && _files
+ ;;
*(open|anon|params))
- # complete hosts: should do cleverer stuff with user names
- complist -k hosts
- ;;
+ # complete hosts: should do cleverer stuff with user names
+ _wanted hosts && _hosts
+ ;;
+
+ *(goto|mark))
+ # complete bookmarks. First decide if ncftp mode is go.
+ _wanted bookmarks || return 1
+ if [[ $words[2] = -*n* ]]; then
+ if [[ -f ~/.ncftp/bookmarks ]]; then
+ _all_labels bookmarks expl bookmark \
+ compadd - $(awk -F, 'NR > 2 { print $1 }' ~/.ncftp/bookmarks)
+ fi
+ else
+ if [[ -f ${ZFTP_BMFILE:=${ZDOTDIR:-$HOME}/.zfbkmarks} ]]; then
+ _all_labels bookmarks expl bookmark \
+ compadd - $(awk '{print $1}' $ZFTP_BMFILE)
+ fi
+ fi
+ ;;
+
+ *session)
+ # complete sessions, excluding the current one.
+ _wanted sessions expl 'another FTP session' \
+ compadd - ${$(zftp session):#$ZFTP_SESSION}
+ ;;
+
+ *transfer)
+ # complete arguments like sess1:file1 sess2:file2
+ if [[ $PREFIX = *:* ]]; then
+ # complete file in the given session
+ _wanted files || return 1
+ local sess=${PREFIX%%:*} oldsess=$ZFTP_SESSION
+ compset -p $(( $#sess + 1 ))
+ [[ -n $sess ]] && zftp session $sess
+ zfget_match $PREFIX $SUFFIX
+ [[ -n $sess && -n $oldsess ]] && zftp session $oldsess
+ else
+ # note here we can complete the current session
+ _wanted sessions expl 'FTP session' compadd -S : - $(zftp session)
+ fi
+ ;;
*)
- # dunno... try ordinary completion after all.
- unset _compskip
- ;;
+ # dunno... try ordinary completion after all.
+ _compskip=''
+ return 1
+ ;;
esac