3
# Complete files on remote systems using SSH (and other programs). Needs
4
# key-based authentication with no passwords or a running ssh-agent to work.
7
# _remote_files [-/] [-g glob] [-h host] -- <cmd> [<cmd options>]
10
# - -/: only complete directories
11
# - -g: specify a pattern to match against files
12
# p, = and * glob qualifiers supported
13
# - -h: specify the remote host, default is ${IPREFIX%:}
16
# - ssh: Additional options for non-interactive use are automatically added
18
# - All other commands are used unaltered.
21
# - _remote_files -- ssh
22
# Use ssh to retrieve the remote paths. The "--" is not optional!
23
# - _remote_files --no-files -- ssh -2 -p 42
24
# Use ssh with the option -2 and -p 42 to retrieve the remote paths and
25
# complete only directories.
26
# - _remote_files -- rsh
27
# Use rsh to retrieve the remote paths.
30
# There should be coloring based on all the different ls -F classifiers.
31
local expl rempat remfiles remdispf remdispd args cmd cmd_args suf ret=1
34
if zstyle -T ":completion:${curcontext}:files" remote-access; then
36
# Parse options to _remote_files. Stops at the first "--".
37
zparseopts -D -E -a args / g:=glob h:=host
39
(( $#host)) && shift host || host="${IPREFIX%:}"
41
# Command to run on the remote system.
45
# Handle arguments to ssh.
46
if [[ $cmd == ssh ]]; then
47
zparseopts -D -E -a cmd_args p: 1 2 4 6 F:
48
cmd_args="-o BatchMode=yes $cmd_args -a -x"
54
then rempat="${PREFIX%%[^./][^/]#}\*"
55
else rempat="${(q)PREFIX%%[^./][^/]#}\*"
58
remfiles=(${(M)${(f)"$(_call_program files $cmd $cmd_args $host ls -d1FL -- "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
61
compset -S '/*' || (( ${args[(I)-/]} )) || suf='remote file'
63
remdispf=(${remfiles:#*/})
64
remdispd=(${(M)remfiles:#*/})
68
glob[2]="${glob[2]/(#b)\(((|^)[p=\*])\)(#e)/}"
69
glob[2]+="${${match[1]/p/\|}/\*/\*}"
70
remdispf=( ${(M)remdispf:#${~glob[2]}} )
75
while _next_label files expl ${suf:-remote directory}; do
77
compadd "$@" "$expl[@]" -d remdispf ${(q)remdispf%[*=|]} && ret=0
78
compadd ${suf:+-S/} -r "/ \t\n\-" "$@" "$expl[@]" -d remdispd \
79
${(q)remdispd%/} && ret=0
85
_message -e remote-files 'remote file'