about summary refs log tree commit diff
path: root/Functions/Zftp/zfget_match
blob: 3a33c98868e7af6aef5020bef4789efec22f5ad2 (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
# function zfget_match {

emulate -L zsh
zmodload -F zsh/files b:zf_ln || return 1

# the zfcd hack:  this may not be necessary here
if [[ $1 == $HOME || $1 == $HOME/* ]]; then
  1="~${1#$HOME}"
fi

if [[ $ZFTP_SYSTEM == UNIX* && $1 == */* ]]; then
  setopt localoptions clobber
  local tmpf=${TMPPREFIX}zfgm$$
  zf_ln -fn =(<<<'') $tmpf || return 1

  if [[ -n $WIDGET ]]; then
    local dir=${1:h}
    [[ $dir = */ ]] || dir="$dir/"
    zftp ls -LF $dir >$tmpf
    local reply
    reply=(${${${(f)"$(<$tmpf)"}##$dir}%\*})
    _wanted files expl 'remote file' compadd -P $dir - $reply
  else
    # On the first argument to ls, we usually get away with a glob.
    zftp ls "$1*$2" >$tmpf
    reply=($(<$tmpf))
  fi
else
  local fcache_name
  zffcache
  if [[ -n $WIDGET ]]; then
    _wanted files expl 'remote file' compadd -F fignore - ${(P)fcache_name}
  else
    reply=(${(P)fcache_name});
  fi
fi
# }