about summary refs log tree commit diff
path: root/Completion/Core/_files
blob: 75cabda817caccc2a4e3062e0f334c4de8716285 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#autoload

local opts opt type=file glob group gopts dopts aopts tmp _file_pat_checked=yes
local hasign ign

zparseopts -a opts \
    '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X: M+: F: \
    'J:=group' 'V:=group'

type="${(@j::M)${(@)tmp#-}#?}"
[[ -n "$type" ]] || type=f
if (( $tmp[(I)-g*] )); then
  gopts=( -g ${(j: :)${(M)tmp:#-g*}#-g} )
else
  gopts=()
fi
(( $opts[(I)-F] )) && hasign=yes

[[ "$group[2]" = files ]] && opts=("$opts[@]" "$group[@]") group=()

ign=()

zstyle -s ":completion:${curcontext}:all-files" file-patterns tmp &&
    [[ -n "$tmp" ]] &&
        aopts=(-g "$tmp")

if zstyle -s ":completion:${curcontext}:directories" file-patterns tmp &&
   [[ -n "$tmp" ]]; then
  dopts=(-g "$tmp")
  if [[ "$type" = (*/*g*|*g*/*) ]]; then
    type=g
  elif [[ "$type" != *[/g]* ]]; then
    type="${type}/"
  fi
else
  dopts=(-/)
fi
if zstyle -s ":completion:${curcontext}:globbed-files" file-patterns tmp &&
   [[ -n "$tmp" ]]; then
  gopts=(-g "$tmp")
  if [[ "$type" != (*/*g*|*g*/*) ]]; then
    if [[ "$type" = *[g/]* ]]; then
      type=g
    else
      type=ga
    fi
  fi
fi

case "$type" in
*/*g*|*g*/*) _tags globbed-files all-files             ;;
*a*g*|*g*a*) _tags globbed-files all-files             ;;
*g*)         _tags globbed-files directories all-files ;;
*/*)         _tags directories all-files               ;;
*)           _tags all-files                           ;;
esac

while _tags; do
  if _requested all-files; then
    if (( $#group )); then
      group[2]=all-files
      _setup all-files
      [[ -z "$hasign" ]] &&
        zstyle -a ":completion:${curcontext}:all-files" ignored-patterns _comp_ignore &&
	  ign=(-F _comp_ignore)
    fi
    _path_files "$opts[@]" "$ign[@]" "$aopts[@]"
    return
  elif _requested directories; then
    if _requested globbed-files; then
      if (( $#group )); then
        group[2]=globbed-files
	_setup globbed-files
        [[ -z "$hasign" ]] &&
          zstyle -a ":completion:${curcontext}:all-files" ignored-patterns _comp_ignore &&
	    ign=(-F _comp_ignore)
      fi
      _path_files "$opts[@]" "$ign[@]" "$dopts[@]" "$gopts[@]" && return 0
    else
      if (( $#group )); then
        group[2]=directories
	_setup directories
        [[ -z "$hasign" ]] &&
          zstyle -a ":completion:${curcontext}:all-files" ignored-patterns _comp_ignore &&
	    ign=(-F _comp_ignore)
      fi
      _path_files "$opts[@]" "$ign[@]" "$dopts[@]" && return 0
    fi
  elif _requested globbed-files; then
    if (( $#group )); then
      group[2]=globbed-files
      _setup globbed-files
      [[ -z "$hasign" ]] &&
        zstyle -a ":completion:${curcontext}:all-files" ignored-patterns _comp_ignore &&
	  ign=(-F _comp_ignore)
    fi
    if [[ "$type" = (*/*g*|*g*/*) ]]; then
      _path_files "$opts[@]" "$ign[@]" "$dopts[@]" "$gopts[@]" && return 0
    else
      _path_files "$opts[@]" "$ign[@]" "$gopts[@]" && return 0
    fi
  fi
done

return 1