_fd
This file
The walk stopped after 200 commits: lines older than 86d6e2d point at it.
Merge pull request #1657 from sharkdp/dependabot/cargo/clap-4.5.23Tavian Barnesbefore adoption86d6e2d
lines 1–285why, one step back1#compdef fd23##4# zsh completion function for fd5#6# Based on ripgrep completion function.7# Originally based on code from the zsh-users project — see copyright notice8# below.910autoload -U is-at-least1112_fd() {13 local curcontext="$curcontext" no='!' ret=114 local -a context line state state_descr _arguments_options fd_types fd_args15 local -A opt_args1617 if is-at-least 5.2; then18 _arguments_options=( -s -S )19 else20 _arguments_options=( -s )21 fi2223 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 {b,block-device}'\:"block devices"'30 {c,char-device}'\:"character devices"'31 {s,socket}'\:"sockets"'32 {p,pipe}'\:"named pipes (FIFOs)"'33 )3435 # Do not complete rare options unless either the current prefix36 # matches one of those options or the user has the `complete-all`37 # style set. Note that this prefix check has to be updated manually to account38 # for all of the potential negation options listed below!39 if40 # (--[bpsu]* => match all options marked with '$no')41 [[ $PREFIX$SUFFIX == --[bopsun]* ]] ||42 zstyle -t ":complete:$curcontext:*" complete-all43 then44 no=45 fi4647 # We make heavy use of argument groups here to prevent the option specs from48 # growing unwieldy. These aren't supported in zsh <5.4, though, so we'll strip49 # them out below if necessary. This makes the exclusions inaccurate on those50 # older versions, but oh well — it's not that big a deal51 fd_args=(52 + '(hidden)' # hidden files53 {-H,--hidden}'[search hidden files/directories]'5455 + '(no-ignore-full)' # all ignore files56 '(no-ignore-partial)'{-I,--no-ignore}"[don't respect .(git|fd)ignore and global ignore files]"57 $no'(no-ignore-partial)*'{-u,--unrestricted}'[alias for --no-ignore, when repeated also alias for --hidden]'5859 + no-ignore-partial # some ignore files60 "(no-ignore-full --no-ignore-vcs)--no-ignore-vcs[don't respect .gitignore files]"61 "!(no-ignore-full --no-global-ignore-file)--no-global-ignore-file[don't respect the global ignore file]"62 $no'(no-ignore-full --no-ignore-parent)--no-ignore-parent[]'6364 + '(case)' # case-sensitivity65 {-s,--case-sensitive}'[perform a case-sensitive search]'66 {-i,--ignore-case}'[perform a case-insensitive search]'6768 + '(regex-pattern)' # regex-based search pattern69 '(no-regex-pattern)--regex[perform a regex-based search (default)]'7071 + '(no-regex-pattern)' # non-regex-based search pattern72 {-g,--glob}'[perform a glob-based search]'73 {-F,--fixed-strings}'[treat pattern as literal string instead of a regex]'7475 + '(no-require-git)'76 "$no(no-ignore-full --no-ignore-vcs --no-require-git)--no-require-git[don't require git repo to respect gitignores]"7778 + '(match-full)' # match against full path79 {-p,--full-path}'[match the pattern against the full path instead of the basename]'8081 + '(follow)' # follow symlinks82 {-L,--follow}'[follow symbolic links to directories]'8384 + '(abs-path)' # show absolute paths85 '(long-listing)'{-a,--absolute-path}'[show absolute paths instead of relative paths]'8687 + '(null-sep)' # use null separator for output88 '(long-listing)'{-0,--print0}'[separate search results by the null character]'8990 + '(long-listing)' # long-listing output91 '(abs-path null-sep max-results exec-cmds)'{-l,--list-details}'[use a long listing format with file metadata]'9293 + '(max-results)' # max number of results94 '(long-listing exec-cmds)--max-results=[limit number of search results to given count and quit]:count'95 '(long-listing exec-cmds)-1[limit to a single search result and quit]'9697 + '(fs-errors)' # file-system errors98 $no'--show-errors[enable the display of filesystem errors]'99100 + '(fs-traversal)' # file-system traversal101 $no"--one-file-system[don't descend into directories on other file systems]"102 '!--mount'103 '!--xdev'104105 + dir-depth # directory depth106 '(--exact-depth -d --max-depth)'{-d+,--max-depth=}'[set max directory depth to descend when searching]:depth'107 '!(--exact-depth -d --max-depth)--maxdepth:depth'108 '(--exact-depth --min-depth)--min-depth=[set directory depth to descend before start searching]:depth'109 '(--exact-depth -d --max-depth --maxdepth --min-depth)--exact-depth=[only search at the exact given directory depth]:depth'110111 + prune # pruning112 "--prune[don't traverse into matching directories]"113114 + filter-misc # filter search115 '*'{-t+,--type=}"[filter search by type]:type:(($fd_types))"116 '*'{-e+,--extension=}'[filter search by file extension]:extension'117 '*'{-E+,--exclude=}'[exclude files/directories that match the given glob pattern]:glob pattern'118 '*'{-S+,--size=}'[limit search by file size]:size limit:->size'119 '(-o --owner)'{-o+,--owner=}'[filter by owning user and/or group]:owner and/or group:->owner'120121 + ignore-file # extra ignore files122 '*--ignore-file=[add a custom, low-precedence ignore-file with .gitignore format]: :_files'123124 + '(filter-mtime-newer)' # filter by files modified after than125 '--changed-within=[limit search to files/directories modified within the given date/duration]:date or duration'126 '--changed-after=[alias for --changed-within]:date/duration'127 '!--change-newer-than=:date/duration'128 '!--newer=:date/duration'129130 + '(filter-mtime-older)' # filter by files modified before than131 '--changed-before=[limit search to files/directories modified before the given date/duration]:date or duration'132 '!--change-older-than=:date/duration'133 '!--older=:date/duration'134135 + '(color)' # colorize output136 {-c+,--color=}'[declare when to colorize search results]:when to colorize:((137 auto\:"show colors if the output goes to an interactive console (default)"138 never\:"do not use colorized output"139 always\:"always use colorized output"140 ))'141142 '--hyperlink=-[add hyperlinks to output paths]::when:(auto never always)'143144 + '(threads)'145 {-j+,--threads=}'[set the number of threads for searching and executing]:number of threads'146147 + '(exec-cmds)' # execute command148 '(long-listing max-results)'{-x+,--exec=}'[execute command for each search result]:command: _command_names -e:*\;::program arguments: _normal'149 '(long-listing max-results)'{-X+,--exec-batch=}'[execute command for all search results at once]:command: _command_names -e:*\;::program arguments: _normal'150 '(long-listing max-results)--batch-size=[max number of args for each -X call]:size'151152 + other153 '!(--max-buffer-time)--max-buffer-time=[set amount of time to buffer before showing output]:time (ms)'154155 + '(about)' # about flags156 '(: * -)'{-h,--help}'[display help message]'157 '(: * -)'{-V,--version}'[display version information]'158159 + path-sep # set path separator for output160 $no'(--path-separator)--path-separator=[set the path separator to use when printing file paths]:path separator'161162 + search-path163 $no'(--base-directory)--base-directory=[change the current working directory to the given path]:directory:_files -/'164 $no'(*)*--search-path=[set search path (instead of positional <path> arguments)]:directory:_files -/'165166 + strip-cwd-prefix167 $no'(strip-cwd-prefix exec-cmds)--strip-cwd-prefix=-[When to strip ./]::when:(always never auto)'168169 + and170 '--and=[additional required search path]:pattern'171172173 + args # positional arguments174 '1: :_guard "^-*" pattern'175 '(--search-path)*:directory:_files -/'176 )177178 # Strip out argument groups where unsupported (see above)179 is-at-least 5.4 ||180 fd_args=( ${(@)args:#(#i)(+|[a-z0-9][a-z0-9_-]#|\([a-z0-9][a-z0-9_-]#\))} )181182 _arguments $_arguments_options : $fd_args && ret=0183184 case ${state} in185 owner)186 compset -P '(\\|)\!'187 if compset -P '*:'; then188 _groups && ret=0189 else190 if191 compset -S ':*' ||192 # Do not add the colon suffix when completing "!user<TAB>193 # (with a starting double-quote) otherwise pressing tab again194 # after the inserted colon "!user:<TAB> will complete history modifiers195 [[ $IPREFIX == (\\|\!)* && ($QIPREFIX == \"* && -z $QISUFFIX) ]]196 then197 _users && ret=0198 else199 local q200 # Since quotes are needed when using the negation prefix !,201 # automatically remove the colon suffix also when closing the quote202 if [[ $QIPREFIX == [\'\"]* ]]; then203 q=${QIPREFIX:0:1}204 fi205 _users -r ": \t\n\-$q" -S : && ret=0206 fi207 fi208 ;;209210 size)211 if compset -P '[-+][0-9]##'; then212 local -a suff=(213 'B:bytes'214 'K:kilobytes (10^3 = 1000 bytes)'215 'M:megabytes (10^6 = 1000^2 bytes)'216 'G:gigabytes (10^9 = 1000^3 bytes)'217 'T:terabytes (10^12 = 1000^4 bytes)'218 'Ki:kibibytes ( 2^10 = 1024 bytes)'219 'Mi:mebibytes ( 2^20 = 1024^2 bytes)'220 'Gi:gigibytes ( 2^30 = 1024^3 bytes)'221 'Ti:tebibytes ( 2^40 = 1024^4 bytes)'222 )223 _describe -t units 'size limit units' suff -V 'units'224 elif compset -P '[-+]'; then225 _message -e 'size limit number (full format: <+-><number><unit>)'226 else227 _values 'size limit prefix (full format: <prefix><number><unit>)' \228 '\+[file size must be greater or equal to]'\229 '-[file size must be less than or equal to]' && ret=0230 fi231 ;;232 esac233234 return ret235}236237_fd "$@"238239# ------------------------------------------------------------------------------240# Copyright (c) 2011 GitHub zsh-users - http://github.com/zsh-users241# All rights reserved.242#243# Redistribution and use in source and binary forms, with or without244# modification, are permitted provided that the following conditions are met:245# * Redistributions of source code must retain the above copyright246# notice, this list of conditions and the following disclaimer.247# * Redistributions in binary form must reproduce the above copyright248# notice, this list of conditions and the following disclaimer in the249# documentation and/or other materials provided with the distribution.250# * Neither the name of the zsh-users nor the251# names of its contributors may be used to endorse or promote products252# derived from this software without specific prior written permission.253#254# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND255# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED256# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE257# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY258# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES259# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;260# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND261# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT262# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS263# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.264# ------------------------------------------------------------------------------265# Description266# -----------267#268# Completion script for fd269#270# ------------------------------------------------------------------------------271# Authors272# -------273#274# * smancill (https://github.com/smancill)275#276# ------------------------------------------------------------------------------277278# Local Variables:279# mode: shell-script280# coding: utf-8-unix281# indent-tabs-mode: nil282# sh-indentation: 2283# sh-basic-offset: 2284# End:285# vim: ft=zsh sw=2 ts=2 et