]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/fd/_fd
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / fd / _fd
1 #compdef fd
2
3 ##
4 # zsh completion function for fd
5 #
6 # Based on ripgrep completion function.
7 # Originally based on code from the zsh-users project — see copyright notice
8 # below.
9
10 autoload -U is-at-least
11
12 _fd() {
13   local curcontext="$curcontext" no='!' ret=1
14   local -a context line state state_descr _arguments_options fd_types fd_args
15   local -A opt_args
16
17   if is-at-least 5.2; then
18     _arguments_options=( -s -S )
19   else
20     _arguments_options=( -s )
21   fi
22
23   fd_types=(
24     {f,file}'\:"regular files"'
25     {d,directory}'\:"directories"'
26     {l,symlink}'\:"symbolic links"'
27     {e,empty}'\:"empty files or directories"'
28     {x,executable}'\:"executable (files)"'
29     {s,socket}'\:"sockets"'
30     {p,pipe}'\:"named pipes (FIFOs)"'
31   )
32
33   # Do not complete rare options unless either the current prefix
34   # matches one of those options or the user has the `complete-all`
35   # style set. Note that this prefix check has to be updated manually to account
36   # for all of the potential negation options listed below!
37   if
38     # (--[bpsu]* => match all options marked with '$no')
39     [[ $PREFIX$SUFFIX == --[bopsu]* ]] ||
40     zstyle -t ":complete:$curcontext:*" complete-all
41   then
42     no=
43   fi
44
45   # We make heavy use of argument groups here to prevent the option specs from
46   # growing unwieldy. These aren't supported in zsh <5.4, though, so we'll strip
47   # them out below if necessary. This makes the exclusions inaccurate on those
48   # older versions, but oh well — it's not that big a deal
49   fd_args=(
50     + '(hidden)' # hidden files
51     {-H,--hidden}'[search hidden files/directories]'
52
53     + '(no-ignore-full)' # all ignore files
54     '(no-ignore-partial)'{-I,--no-ignore}"[don't respect .(git|fd)ignore and global ignore files]"
55     $no'(no-ignore-partial)*'{-u,--unrestricted}'[alias for --no-ignore, when repeated also alias for --hidden]'
56
57     + no-ignore-partial # some ignore files
58     "(no-ignore-full --no-ignore-vcs)--no-ignore-vcs[don't respect .gitignore files]"
59     "!(no-ignore-full --no-global-ignore-file)--no-global-ignore-file[don't respect the global ignore file]"
60     $no'(no-ignore-full --no-ignore-parent)--no-ignore-parent[]'
61
62     + '(case)' # case-sensitivity
63     {-s,--case-sensitive}'[perform a case-sensitive search]'
64     {-i,--ignore-case}'[perform a case-insensitive search]'
65
66     + '(regex-pattern)' # regex-based search pattern
67     '(no-regex-pattern)--regex[perform a regex-based search (default)]'
68
69     + '(no-regex-pattern)' # non-regex-based search pattern
70     {-g,--glob}'[perform a glob-based search]'
71     {-F,--fixed-strings}'[treat pattern as literal string instead of a regex]'
72
73     + '(match-full)' # match against full path
74     {-p,--full-path}'[match the pattern against the full path instead of the basename]'
75
76     + '(follow)' # follow symlinks
77     {-L,--follow}'[follow symbolic links to directories]'
78
79     + '(abs-path)' # show absolute paths
80     '(long-listing)'{-a,--absolute-path}'[show absolute paths instead of relative paths]'
81
82     + '(null-sep)' # use null separator for output
83     '(long-listing)'{-0,--print0}'[separate search results by the null character]'
84
85     + '(long-listing)' # long-listing output
86     '(abs-path null-sep max-results exec-cmds)'{-l,--list-details}'[use a long listing format with file metadata]'
87
88     + '(max-results)' # max number of results
89     '(long-listing exec-cmds)--max-results=[limit number of search results to given count and quit]:count'
90     '(long-listing exec-cmds)-1[limit to a single search result and quit]'
91
92     + '(fs-errors)' # file-system errors
93     $no'--show-errors[enable the display of filesystem errors]'
94
95     + '(fs-traversal)' # file-system traversal
96     $no"--one-file-system[don't descend into directories on other file systems]"
97     '!--mount'
98     '!--xdev'
99
100     + dir-depth # directory depth
101     '(--exact-depth -d --max-depth)'{-d+,--max-depth=}'[set max directory depth to descend when searching]:depth'
102     '!(--exact-depth -d --max-depth)--maxdepth:depth'
103     '(--exact-depth --min-depth)--min-depth=[set directory depth to descend before start searching]:depth'
104     '(--exact-depth -d --max-depth --maxdepth --min-depth)--exact-depth=[only search at the exact given directory depth]:depth'
105
106     + prune # pruning
107     "--prune[don't traverse into matching directories]"
108
109     + filter-misc # filter search
110     '*'{-t+,--type=}"[filter search by type]:type:(($fd_types))"
111     '*'{-e+,--extension=}'[filter search by file extension]:extension'
112     '*'{-E+,--exclude=}'[exclude files/directories that match the given glob pattern]:glob pattern'
113     '*'{-S+,--size=}'[limit search by file size]:size limit:->size'
114     '(-o --owner)'{-o+,--owner=}'[filter by owning user and/or group]:owner and/or group:->owner'
115
116     + ignore-file # extra ignore files
117     '*--ignore-file=[add a custom, low-precedence ignore-file with .gitignore format]: :_files'
118
119     + '(filter-mtime-newer)' # filter by files modified after than
120     '--changed-within=[limit search to files/directories modified within the given date/duration]:date or duration'
121     '!--change-newer-than=:date/duration'
122     '!--newer=:date/duration'
123
124     + '(filter-mtime-older)' # filter by files modified before than
125     '--changed-before=[limit search to files/directories modified before the given date/duration]:date or duration'
126     '!--change-older-than=:date/duration'
127     '!--older=:date/duration'
128
129     + '(color)' # colorize output
130     {-c+,--color=}'[declare when to colorize search results]:when to colorize:((
131       auto\:"show colors if the output goes to an interactive console (default)"
132       never\:"do not use colorized output"
133       always\:"always use colorized output"
134     ))'
135
136     + '(threads)'
137     {-j+,--threads=}'[set the number of threads for searching and executing]:number of threads'
138
139     + '(exec-cmds)' # execute command
140     '(long-listing max-results)'{-x+,--exec=}'[execute command for each search result]:command: _command_names -e:*\;::program arguments: _normal'
141     '(long-listing max-results)'{-X+,--exec-batch=}'[execute command for all search results at once]:command: _command_names -e:*\;::program arguments: _normal'
142     '(long-listing max-results)--batch-size=[max number of args for each -X call]:size'
143
144     + other
145     '!(--max-buffer-time)--max-buffer-time=[set amount of time to buffer before showing output]:time (ms)'
146
147     + '(about)' # about flags
148     '(: * -)'{-h,--help}'[display help message]'
149     '(: * -)'{-v,--version}'[display version information]'
150
151     + path-sep # set path separator for output
152     $no'(--path-separator)--path-separator=[set the path separator to use when printing file paths]:path separator'
153
154     + search-path
155     $no'(--base-directory)--base-directory=[change the current working directory to the given path]:directory:_files -/'
156     $no'(*)*--search-path=[set search path (instead of positional <path> arguments)]:directory:_files -/'
157
158     + strip-cwd-prefix
159     $no'(strip-cwd-prefix exec-cmds)--strip-cwd-prefix[Strip ./ prefix when output is redirected]'
160
161     + args # positional arguments
162     '1: :_guard "^-*" pattern'
163     '(--search-path)*:directory:_files -/'
164   )
165
166   # Strip out argument groups where unsupported (see above)
167   is-at-least 5.4 ||
168   fd_args=( ${(@)args:#(#i)(+|[a-z0-9][a-z0-9_-]#|\([a-z0-9][a-z0-9_-]#\))} )
169
170   _arguments $_arguments_options : $fd_args && ret=0
171
172   case ${state} in
173     owner)
174       compset -P '(\\|)\!'
175       if compset -P '*:'; then
176         _groups && ret=0
177       else
178         if
179           compset -S ':*' ||
180           # Do not add the colon suffix when completing "!user<TAB>
181           # (with a starting double-quote) otherwise pressing tab again
182           # after the inserted colon "!user:<TAB> will complete history modifiers
183           [[ $IPREFIX == (\\|\!)*  && ($QIPREFIX == \"* && -z $QISUFFIX) ]]
184         then
185           _users && ret=0
186         else
187           local q
188           # Since quotes are needed when using the negation prefix !,
189           # automatically remove the colon suffix also when closing the quote
190           if [[ $QIPREFIX == [\'\"]* ]]; then
191             q=${QIPREFIX:0:1}
192           fi
193           _users -r ": \t\n\-$q" -S : && ret=0
194         fi
195       fi
196       ;;
197
198     size)
199       if compset -P '[-+][0-9]##'; then
200         local -a suff=(
201           'B:bytes'
202           'K:kilobytes  (10^3  = 1000   bytes)'
203           'M:megabytes  (10^6  = 1000^2 bytes)'
204           'G:gigabytes  (10^9  = 1000^3 bytes)'
205           'T:terabytes  (10^12 = 1000^4 bytes)'
206           'Ki:kibibytes  ( 2^10 = 1024   bytes)'
207           'Mi:mebibytes  ( 2^20 = 1024^2 bytes)'
208           'Gi:gigibytes  ( 2^30 = 1024^3 bytes)'
209           'Ti:tebibytes  ( 2^40 = 1024^4 bytes)'
210         )
211         _describe -t units 'size limit units' suff -V 'units'
212       elif compset -P '[-+]'; then
213         _message -e 'size limit number (full format: <+-><number><unit>)'
214       else
215         _values 'size limit prefix (full format: <prefix><number><unit>)' \
216           '\+[file size must be greater or equal to]'\
217           '-[file size must be less than or equal to]' && ret=0
218       fi
219       ;;
220   esac
221
222   return ret
223 }
224
225 _fd "$@"
226
227 # ------------------------------------------------------------------------------
228 # Copyright (c) 2011 GitHub zsh-users - http://github.com/zsh-users
229 # All rights reserved.
230 #
231 # Redistribution and use in source and binary forms, with or without
232 # modification, are permitted provided that the following conditions are met:
233 #     * Redistributions of source code must retain the above copyright
234 #       notice, this list of conditions and the following disclaimer.
235 #     * Redistributions in binary form must reproduce the above copyright
236 #       notice, this list of conditions and the following disclaimer in the
237 #       documentation and/or other materials provided with the distribution.
238 #     * Neither the name of the zsh-users nor the
239 #       names of its contributors may be used to endorse or promote products
240 #       derived from this software without specific prior written permission.
241 #
242 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
243 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
244 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
245 # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
246 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
247 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
248 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
249 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
250 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
251 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
252 # ------------------------------------------------------------------------------
253 # Description
254 # -----------
255 #
256 #  Completion script for fd
257 #
258 # ------------------------------------------------------------------------------
259 # Authors
260 # -------
261 #
262 #  * smancill (https://github.com/smancill)
263 #
264 # ------------------------------------------------------------------------------
265
266 # Local Variables:
267 # mode: shell-script
268 # coding: utf-8-unix
269 # indent-tabs-mode: nil
270 # sh-indentation: 2
271 # sh-basic-offset: 2
272 # End:
273 # vim: ft=zsh sw=2 ts=2 et