about summary refs log tree commit diff
path: root/Completion/Builtins/_zftp
blob: 7b3ee0f9723990d76922c9c3ce1ac2d116ecc14a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#compdef -p zf*

# Don't try any more completion after this.
_compskip=all

# Completion for zftp builtin and zf* functions.  The functions
# zfcd_match and zfget_match (used for old-style completion)
# need to be installed for remote file and directory completion to work.

local subcom expl

if [[ $words[1] = zftp ]]; then
  if [[ $CURRENT -eq 2 ]]; then
    _description expl sub-command
    compadd "$expl[@]" open params user login type ascii binary mode put \
      putat get getat append appendat ls dir local remote mkdir rmdir
    return
  fi
  subcom=$words[2]
else
  subcom=$words[1]
fi

case $subcom in
  *(cd|ls|dir))
    # complete remote directories; we could be smarter about hiding prefixes
    zfcd_match $PREFIX $SUFFIX
    _description expl 'remote directory'
    (( $#reply )) && compadd "$expl[@]" -S/ -q - $reply
    ;;

  *(get(|at)|gcp|delete|remote))
    # complete remote files
    zfget_match $PREFIX $SUFFIX
    _description expl 'remote file'
    (( $#reply )) && compadd "$expl[@]" -F fignore - $reply
    ;;

  *(put(|at)|pcp))
    # complete local files
    _files
    ;;

  *(open|anon|params))
    # complete hosts:  should do cleverer stuff with user names
    _hosts
    ;;

  *(goto|mark))
    # complete bookmarks.  First decide if ncftp mode is go.
    _description expl bookmark
    if [[ $words[2] = -*n* ]]; then
      if [[ -f ~/.ncftp/bookmarks ]]; then
        compadd "$expl[@]" - $(awk -F, 'NR > 2 { print $1 }' ~/.ncftp/bookmarks)
      fi
    else
      if [[ -f ${ZFTP_BMFILE:=${ZDOTDIR:-$HOME}/.zfbkmarks} ]]; then
        compadd "$expl[@]" - $(awk '{print $1}' $ZFTP_BMFILE)
      fi
    fi
    ;;

  *)
    # dunno... try ordinary completion after all.
    unset _compskip
    return 1
    ;;
esac