~ubuntu-branches/ubuntu/utopic/zsh/utopic-proposed

« back to all changes in this revision

Viewing changes to Completion/Unix/Type/_remote_files

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-08-02 13:37:21 UTC
  • mfrom: (35.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130802133721-3j6vii96vovrdwoc
Tags: 5.0.2-3ubuntu1
* Merge from Debian, remaining changes - support cross-compiling:
  - Adjust upstream autoconf cross-compile default fallbacks.
  - Skip zcompile when cross-compiling.
  - Add libelf-dev dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#autoload
 
2
 
 
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.
 
5
#
 
6
# Usage:
 
7
#   _remote_files [-/] [-g glob] [-h host] -- <cmd> [<cmd options>]
 
8
#
 
9
# 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%:}
 
14
#
 
15
# Commands:
 
16
# - ssh: Additional options for non-interactive use are automatically added
 
17
#        (see below).
 
18
# - All other commands are used unaltered.
 
19
#
 
20
# Examples:
 
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.
 
28
 
 
29
 
 
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
 
32
local glob host
 
33
 
 
34
if zstyle -T ":completion:${curcontext}:files" remote-access; then
 
35
 
 
36
  # Parse options to _remote_files. Stops at the first "--".
 
37
  zparseopts -D -E -a args / g:=glob h:=host
 
38
  shift
 
39
  (( $#host)) && shift host || host="${IPREFIX%:}"
 
40
 
 
41
  # Command to run on the remote system.
 
42
  cmd="$1"
 
43
  shift
 
44
 
 
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"
 
49
  else
 
50
    cmd_args="$@"
 
51
  fi
 
52
 
 
53
  if [[ -z $QIPREFIX ]]
 
54
    then rempat="${PREFIX%%[^./][^/]#}\*"
 
55
    else rempat="${(q)PREFIX%%[^./][^/]#}\*"
 
56
  fi
 
57
 
 
58
  remfiles=(${(M)${(f)"$(_call_program files $cmd $cmd_args $host ls -d1FL -- "$rempat" 2>/dev/null)"}%%[^/]#(|/)})
 
59
 
 
60
  compset -P '*/'
 
61
  compset -S '/*' || (( ${args[(I)-/]} )) || suf='remote file'
 
62
 
 
63
  remdispf=(${remfiles:#*/})
 
64
  remdispd=(${(M)remfiles:#*/})
 
65
 
 
66
  if (( $#glob )); then
 
67
    match=( '(|[*=|])' )
 
68
    glob[2]="${glob[2]/(#b)\(((|^)[p=\*])\)(#e)/}"
 
69
    glob[2]+="${${match[1]/p/\|}/\*/\*}"
 
70
    remdispf=( ${(M)remdispf:#${~glob[2]}} )
 
71
  fi
 
72
 
 
73
  _tags files
 
74
  while _tags; do
 
75
    while _next_label files expl ${suf:-remote directory}; do
 
76
      [[ -n $suf ]] &&
 
77
          compadd "$@" "$expl[@]" -d remdispf ${(q)remdispf%[*=|]} && ret=0
 
78
      compadd ${suf:+-S/} -r "/ \t\n\-" "$@" "$expl[@]" -d remdispd \
 
79
        ${(q)remdispd%/} && ret=0
 
80
    done
 
81
    (( ret )) || return 0
 
82
  done
 
83
  return ret
 
84
else
 
85
    _message -e remote-files 'remote file'
 
86
fi