_ripgrep 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. #compdef rg
  2. ##
  3. # zsh completion function for ripgrep
  4. #
  5. # Run ci/test_complete.sh after building to ensure that the options supported by
  6. # this function stay in synch with the `rg` binary.
  7. #
  8. # For convenience, a completion reference guide is included at the bottom of
  9. # this file.
  10. #
  11. # Originally based on code from the zsh-users project — see copyright notice
  12. # below.
  13. _rg() {
  14. local curcontext=$curcontext no='!' descr ret=1
  15. local -a context line state state_descr args tmp suf
  16. local -A opt_args
  17. # ripgrep has many options which negate the effect of a more common one — for
  18. # example, `--no-column` to negate `--column`, and `--messages` to negate
  19. # `--no-messages`. There are so many of these, and they're so infrequently
  20. # used, that some users will probably find it irritating if they're completed
  21. # indiscriminately, so let's not do that unless either the current prefix
  22. # matches one of those negation options or the user has the `complete-all`
  23. # style set. Note that this prefix check has to be updated manually to account
  24. # for all of the potential negation options listed below!
  25. if
  26. # We also want to list all of these options during testing
  27. [[ $_RG_COMPLETE_LIST_ARGS == (1|t*|y*) ]] ||
  28. # (--[imnp]* => --ignore*, --messages, --no-*, --pcre2-unicode)
  29. [[ $PREFIX$SUFFIX == --[imnp]* ]] ||
  30. zstyle -t ":complete:$curcontext:*" complete-all
  31. then
  32. no=
  33. fi
  34. # We make heavy use of argument groups here to prevent the option specs from
  35. # growing unwieldy. These aren't supported in zsh <5.4, though, so we'll strip
  36. # them out below if necessary. This makes the exclusions inaccurate on those
  37. # older versions, but oh well — it's not that big a deal
  38. args=(
  39. + '(exclusive)' # Misc. fully exclusive options
  40. '(: * -)'{-h,--help}'[display help information]'
  41. '(: * -)'{-V,--version}'[display version information]'
  42. '(: * -)'--pcre2-version'[print the version of PCRE2 used by ripgrep, if available]'
  43. + '(buffered)' # buffering options
  44. '--line-buffered[force line buffering]'
  45. $no"--no-line-buffered[don't force line buffering]"
  46. '--block-buffered[force block buffering]'
  47. $no"--no-block-buffered[don't force block buffering]"
  48. + '(case)' # Case-sensitivity options
  49. {-i,--ignore-case}'[search case-insensitively]'
  50. {-s,--case-sensitive}'[search case-sensitively]'
  51. {-S,--smart-case}'[search case-insensitively if pattern is all lowercase]'
  52. + '(context-a)' # Context (after) options
  53. '(context-c)'{-A+,--after-context=}'[specify lines to show after each match]:number of lines'
  54. + '(context-b)' # Context (before) options
  55. '(context-c)'{-B+,--before-context=}'[specify lines to show before each match]:number of lines'
  56. + '(context-c)' # Context (combined) options
  57. '(context-a context-b)'{-C+,--context=}'[specify lines to show before and after each match]:number of lines'
  58. + '(column)' # Column options
  59. '--column[show column numbers for matches]'
  60. $no"--no-column[don't show column numbers for matches]"
  61. + '(count)' # Counting options
  62. {-c,--count}'[only show count of matching lines for each file]'
  63. '--count-matches[only show count of individual matches for each file]'
  64. + '(encoding)' # Encoding options
  65. {-E+,--encoding=}'[specify text encoding of files to search]: :_rg_encodings'
  66. $no'--no-encoding[use default text encoding]'
  67. + file # File-input options
  68. '(1)*'{-f+,--file=}'[specify file containing patterns to search for]: :_files'
  69. + '(file-match)' # Files with/without match options
  70. '(stats)'{-l,--files-with-matches}'[only show names of files with matches]'
  71. '(stats)--files-without-match[only show names of files without matches]'
  72. + '(file-name)' # File-name options
  73. {-H,--with-filename}'[show file name for matches]'
  74. {-I,--no-filename}"[don't show file name for matches]"
  75. + '(file-system)' # File system options
  76. "--one-file-system[don't descend into directories on other file systems]"
  77. $no'--no-one-file-system[descend into directories on other file systems]'
  78. + '(fixed)' # Fixed-string options
  79. {-F,--fixed-strings}'[treat pattern as literal string instead of regular expression]'
  80. $no"--no-fixed-strings[don't treat pattern as literal string]"
  81. + '(follow)' # Symlink-following options
  82. {-L,--follow}'[follow symlinks]'
  83. $no"--no-follow[don't follow symlinks]"
  84. + glob # File-glob options
  85. '*'{-g+,--glob=}'[include/exclude files matching specified glob]:glob'
  86. '*--iglob=[include/exclude files matching specified case-insensitive glob]:glob'
  87. + '(glob-case-insensitive)' # File-glob case sensitivity options
  88. '--glob-case-insensitive[treat -g/--glob patterns case insensitively]'
  89. $no'--no-glob-case-insensitive[treat -g/--glob patterns case sensitively]'
  90. + '(heading)' # Heading options
  91. '(pretty-vimgrep)--heading[show matches grouped by file name]'
  92. "(pretty-vimgrep)--no-heading[don't show matches grouped by file name]"
  93. + '(hidden)' # Hidden-file options
  94. '--hidden[search hidden files and directories]'
  95. $no"--no-hidden[don't search hidden files and directories]"
  96. + '(hybrid)' # hybrid regex options
  97. '--auto-hybrid-regex[dynamically use PCRE2 if necessary]'
  98. $no"--no-auto-hybrid-regex[don't dynamically use PCRE2 if necessary]"
  99. + '(ignore)' # Ignore-file options
  100. "(--no-ignore-global --no-ignore-parent --no-ignore-vcs --no-ignore-dot)--no-ignore[don't respect ignore files]"
  101. $no'(--ignore-global --ignore-parent --ignore-vcs --ignore-dot)--ignore[respect ignore files]'
  102. + '(ignore-file-case-insensitive)' # Ignore-file case sensitivity options
  103. '--ignore-file-case-insensitive[process ignore files case insensitively]'
  104. $no'--no-ignore-file-case-insensitive[process ignore files case sensitively]'
  105. + '(ignore-global)' # Global ignore-file options
  106. "--no-ignore-global[don't respect global ignore files]"
  107. $no'--ignore-global[respect global ignore files]'
  108. + '(ignore-parent)' # Parent ignore-file options
  109. "--no-ignore-parent[don't respect ignore files in parent directories]"
  110. $no'--ignore-parent[respect ignore files in parent directories]'
  111. + '(ignore-vcs)' # VCS ignore-file options
  112. "--no-ignore-vcs[don't respect version control ignore files]"
  113. $no'--ignore-vcs[respect version control ignore files]'
  114. + '(ignore-dot)' # .ignore-file options
  115. "--no-ignore-dot[don't respect .ignore files]"
  116. $no'--ignore-dot[respect .ignore files]'
  117. + '(json)' # JSON options
  118. '--json[output results in JSON Lines format]'
  119. $no"--no-json[don't output results in JSON Lines format]"
  120. + '(line-number)' # Line-number options
  121. {-n,--line-number}'[show line numbers for matches]'
  122. {-N,--no-line-number}"[don't show line numbers for matches]"
  123. + '(line-terminator)' # Line-terminator options
  124. '--crlf[use CRLF as line terminator]'
  125. $no"--no-crlf[don't use CRLF as line terminator]"
  126. '(text)--null-data[use NUL as line terminator]'
  127. + '(max-columns-preview)' # max column preview options
  128. '--max-columns-preview[show preview for long lines (with -M)]'
  129. $no"--no-max-columns-preview[don't show preview for long lines (with -M)]"
  130. + '(max-depth)' # Directory-depth options
  131. '--max-depth=[specify max number of directories to descend]:number of directories'
  132. '!--maxdepth=:number of directories'
  133. + '(messages)' # Error-message options
  134. '(--no-ignore-messages)--no-messages[suppress some error messages]'
  135. $no"--messages[don't suppress error messages affected by --no-messages]"
  136. + '(messages-ignore)' # Ignore-error message options
  137. "--no-ignore-messages[don't show ignore-file parse error messages]"
  138. $no'--ignore-messages[show ignore-file parse error messages]'
  139. + '(mmap)' # mmap options
  140. '--mmap[search using memory maps when possible]'
  141. "--no-mmap[don't search using memory maps]"
  142. + '(multiline)' # Multiline options
  143. {-U,--multiline}'[permit matching across multiple lines]'
  144. $no'(multiline-dotall)--no-multiline[restrict matches to at most one line each]'
  145. + '(multiline-dotall)' # Multiline DOTALL options
  146. '(--no-multiline)--multiline-dotall[allow "." to match newline (with -U)]'
  147. $no"(--no-multiline)--no-multiline-dotall[don't allow \".\" to match newline (with -U)]"
  148. + '(only)' # Only-match options
  149. {-o,--only-matching}'[show only matching part of each line]'
  150. + '(passthru)' # Pass-through options
  151. '(--vimgrep)--passthru[show both matching and non-matching lines]'
  152. '!(--vimgrep)--passthrough'
  153. + '(pcre2)' # PCRE2 options
  154. {-P,--pcre2}'[enable matching with PCRE2]'
  155. $no'(pcre2-unicode)--no-pcre2[disable matching with PCRE2]'
  156. + '(pcre2-unicode)' # PCRE2 Unicode options
  157. $no'(--no-pcre2 --no-pcre2-unicode)--pcre2-unicode[enable PCRE2 Unicode mode (with -P)]'
  158. '(--no-pcre2 --pcre2-unicode)--no-pcre2-unicode[disable PCRE2 Unicode mode (with -P)]'
  159. + '(pre)' # Preprocessing options
  160. '(-z --search-zip)--pre=[specify preprocessor utility]:preprocessor utility:_command_names -e'
  161. $no'--no-pre[disable preprocessor utility]'
  162. + pre-glob # Preprocessing glob options
  163. '*--pre-glob[include/exclude files for preprocessing with --pre]'
  164. + '(pretty-vimgrep)' # Pretty/vimgrep display options
  165. '(heading)'{-p,--pretty}'[alias for --color=always --heading -n]'
  166. '(heading passthru)--vimgrep[show results in vim-compatible format]'
  167. + regexp # Explicit pattern options
  168. '(1 file)*'{-e+,--regexp=}'[specify pattern]:pattern'
  169. + '(replace)' # Replacement options
  170. {-r+,--replace=}'[specify string used to replace matches]:replace string'
  171. + '(sort)' # File-sorting options
  172. '(threads)--sort=[sort results in ascending order (disables parallelism)]:sort method:((
  173. none\:"no sorting"
  174. path\:"sort by file path"
  175. modified\:"sort by last modified time"
  176. accessed\:"sort by last accessed time"
  177. created\:"sort by creation time"
  178. ))'
  179. '(threads)--sortr=[sort results in descending order (disables parallelism)]:sort method:((
  180. none\:"no sorting"
  181. path\:"sort by file path"
  182. modified\:"sort by last modified time"
  183. accessed\:"sort by last accessed time"
  184. created\:"sort by creation time"
  185. ))'
  186. '!(threads)--sort-files[sort results by file path (disables parallelism)]'
  187. + '(stats)' # Statistics options
  188. '(--files file-match)--stats[show search statistics]'
  189. $no"--no-stats[don't show search statistics]"
  190. + '(text)' # Binary-search options
  191. {-a,--text}'[search binary files as if they were text]'
  192. "--binary[search binary files, don't print binary data]"
  193. $no"--no-binary[don't search binary files]"
  194. $no"(--null-data)--no-text[don't search binary files as if they were text]"
  195. + '(threads)' # Thread-count options
  196. '(sort)'{-j+,--threads=}'[specify approximate number of threads to use]:number of threads'
  197. + '(trim)' # Trim options
  198. '--trim[trim any ASCII whitespace prefix from each line]'
  199. $no"--no-trim[don't trim ASCII whitespace prefix from each line]"
  200. + type # Type options
  201. '*'{-t+,--type=}'[only search files matching specified type]: :_rg_types'
  202. '*--type-add=[add new glob for specified file type]: :->typespec'
  203. '*--type-clear=[clear globs previously defined for specified file type]: :_rg_types'
  204. # This should actually be exclusive with everything but other type options
  205. '(: *)--type-list[show all supported file types and their associated globs]'
  206. '*'{-T+,--type-not=}"[don't search files matching specified file type]: :_rg_types"
  207. + '(word-line)' # Whole-word/line match options
  208. {-w,--word-regexp}'[only show matches surrounded by word boundaries]'
  209. {-x,--line-regexp}'[only show matches surrounded by line boundaries]'
  210. + '(zip)' # Compression options
  211. '(--pre)'{-z,--search-zip}'[search in compressed files]'
  212. $no"--no-search-zip[don't search in compressed files]"
  213. + misc # Other options — no need to separate these at the moment
  214. '(-b --byte-offset)'{-b,--byte-offset}'[show 0-based byte offset for each matching line]'
  215. '--color=[specify when to use colors in output]:when:((
  216. never\:"never use colors"
  217. auto\:"use colors or not based on stdout, TERM, etc."
  218. always\:"always use colors"
  219. ansi\:"always use ANSI colors (even on Windows)"
  220. ))'
  221. '*--colors=[specify color and style settings]: :->colorspec'
  222. '--context-separator=[specify string used to separate non-continuous context lines in output]:separator'
  223. '--debug[show debug messages]'
  224. '--dfa-size-limit=[specify upper size limit of generated DFA]:DFA size (bytes)'
  225. "(1 stats)--files[show each file that would be searched (but don't search)]"
  226. '*--ignore-file=[specify additional ignore file]:ignore file:_files'
  227. '(-v --invert-match)'{-v,--invert-match}'[invert matching]'
  228. '(-M --max-columns)'{-M+,--max-columns=}'[specify max length of lines to print]:number of bytes'
  229. '(-m --max-count)'{-m+,--max-count=}'[specify max number of matches per file]:number of matches'
  230. '--max-filesize=[specify size above which files should be ignored]:file size (bytes)'
  231. "--no-config[don't load configuration files]"
  232. '(-0 --null)'{-0,--null}'[print NUL byte after file names]'
  233. '--path-separator=[specify path separator to use when printing file names]:separator'
  234. '(-q --quiet)'{-q,--quiet}'[suppress normal output]'
  235. '--regex-size-limit=[specify upper size limit of compiled regex]:regex size (bytes)'
  236. '*'{-u,--unrestricted}'[reduce level of "smart" searching]'
  237. + operand # Operands
  238. '(--files --type-list file regexp)1: :_guard "^-*" pattern'
  239. '(--type-list)*: :_files'
  240. )
  241. # This is used with test_complete.sh to verify that there are no options
  242. # listed in the help output that aren't also defined here
  243. [[ $_RG_COMPLETE_LIST_ARGS == (1|t*|y*) ]] && {
  244. print -rl - $args
  245. return 0
  246. }
  247. # Strip out argument groups where unsupported (see above)
  248. [[ $ZSH_VERSION == (4|5.<0-3>)(.*)# ]] &&
  249. args=( ${(@)args:#(#i)(+|[a-z0-9][a-z0-9_-]#|\([a-z0-9][a-z0-9_-]#\))} )
  250. _arguments -C -s -S : $args && ret=0
  251. case $state in
  252. colorspec)
  253. if [[ ${IPREFIX#--*=}$PREFIX == [^:]# ]]; then
  254. suf=( -qS: )
  255. tmp=(
  256. 'column:specify coloring for column numbers'
  257. 'line:specify coloring for line numbers'
  258. 'match:specify coloring for match text'
  259. 'path:specify coloring for file names'
  260. )
  261. descr='color/style type'
  262. elif [[ ${IPREFIX#--*=}$PREFIX == (column|line|match|path):[^:]# ]]; then
  263. suf=( -qS: )
  264. tmp=(
  265. 'none:clear color/style for type'
  266. 'bg:specify background color'
  267. 'fg:specify foreground color'
  268. 'style:specify text style'
  269. )
  270. descr='color/style attribute'
  271. elif [[ ${IPREFIX#--*=}$PREFIX == [^:]##:(bg|fg):[^:]# ]]; then
  272. tmp=( black blue green red cyan magenta yellow white )
  273. descr='color name or r,g,b'
  274. elif [[ ${IPREFIX#--*=}$PREFIX == [^:]##:style:[^:]# ]]; then
  275. tmp=( {,no}bold {,no}intense {,no}underline )
  276. descr='style name'
  277. else
  278. _message -e colorspec 'no more arguments'
  279. fi
  280. (( $#tmp )) && {
  281. compset -P '*:'
  282. _describe -t colorspec $descr tmp $suf && ret=0
  283. }
  284. ;;
  285. typespec)
  286. if compset -P '[^:]##:include:'; then
  287. _sequence -s , _rg_types && ret=0
  288. # @todo This bit in particular could be better, but it's a little
  289. # complex, and attempting to solve it seems to run us up against a crash
  290. # bug — zsh # 40362
  291. elif compset -P '[^:]##:'; then
  292. _message 'glob or include directive' && ret=1
  293. elif [[ ! -prefix *:* ]]; then
  294. _rg_types -qS : && ret=0
  295. fi
  296. ;;
  297. esac
  298. return ret
  299. }
  300. # Complete encodings
  301. _rg_encodings() {
  302. local -a expl
  303. local -aU _encodings
  304. # This is impossible to read, but these encodings rarely if ever change, so it
  305. # probably doesn't matter. They are derived from the list given here:
  306. # https://encoding.spec.whatwg.org/#concept-encoding-get
  307. _encodings=(
  308. {{,us-}ascii,arabic,chinese,cyrillic,greek{,8},hebrew,korean}
  309. logical visual mac {,cs}macintosh x-mac-{cyrillic,roman,ukrainian}
  310. 866 ibm{819,866} csibm866
  311. big5{,-hkscs} {cn-,cs}big5 x-x-big5
  312. cp{819,866,125{0..8}} x-cp125{0..8}
  313. csiso2022{jp,kr} csiso8859{6,8}{e,i}
  314. csisolatin{{1..6},9} csisolatin{arabic,cyrillic,greek,hebrew}
  315. ecma-{114,118} asmo-708 elot_928 sun_eu_greek
  316. euc-{jp,kr} x-euc-jp cseuckr cseucpkdfmtjapanese
  317. {,x-}gbk csiso58gb231280 gb18030 {,cs}gb2312 gb_2312{,-80} hz-gb-2312
  318. iso-2022-{cn,cn-ext,jp,kr}
  319. iso8859{,-}{{1..11},13,14,15}
  320. iso-8859-{{1..11},{6,8}-{e,i},13,14,15,16} iso_8859-{{1..9},15}
  321. iso_8859-{1,2,6,7}:1987 iso_8859-{3,4,5,8}:1988 iso_8859-9:1989
  322. iso-ir-{58,100,101,109,110,126,127,138,144,148,149,157}
  323. koi{,8,8-r,8-ru,8-u,8_r} cskoi8r
  324. ks_c_5601-{1987,1989} ksc{,_}5691 csksc56011987
  325. latin{1..6} l{{1..6},9}
  326. shift{-,_}jis csshiftjis {,x-}sjis ms_kanji ms932
  327. utf{,-}8 utf-16{,be,le} unicode-1-1-utf-8
  328. windows-{31j,874,949,125{0..8}} dos-874 tis-620 ansi_x3.4-1968
  329. x-user-defined auto none
  330. )
  331. _wanted encodings expl encoding compadd -a "$@" - _encodings
  332. }
  333. # Complete file types
  334. _rg_types() {
  335. local -a expl
  336. local -aU _types
  337. _types=( ${(@)${(f)"$( _call_program types rg --type-list )"}%%:*} )
  338. _wanted types expl 'file type' compadd -a "$@" - _types
  339. }
  340. _rg "$@"
  341. ################################################################################
  342. # ZSH COMPLETION REFERENCE
  343. #
  344. # For the convenience of developers who aren't especially familiar with zsh
  345. # completion functions, a brief reference guide follows. This is in no way
  346. # comprehensive; it covers just enough of the basic structure, syntax, and
  347. # conventions to help someone make simple changes like adding new options. For
  348. # more complete documentation regarding zsh completion functions, please see the
  349. # following:
  350. #
  351. # * http://zsh.sourceforge.net/Doc/Release/Completion-System.html
  352. # * https://github.com/zsh-users/zsh/blob/master/Etc/completion-style-guide
  353. #
  354. # OVERVIEW
  355. #
  356. # Most zsh completion functions are defined in terms of `_arguments`, which is a
  357. # shell function that takes a series of argument specifications. The specs for
  358. # `rg` are stored in an array, which is common for more complex functions; the
  359. # elements of the array are passed to `_arguments` on invocation.
  360. #
  361. # ARGUMENT-SPECIFICATION SYNTAX
  362. #
  363. # The following is a contrived example of the argument specs for a simple tool:
  364. #
  365. # '(: * -)'{-h,--help}'[display help information]'
  366. # '(-q -v --quiet --verbose)'{-q,--quiet}'[decrease output verbosity]'
  367. # '!(-q -v --quiet --verbose)--silent'
  368. # '(-q -v --quiet --verbose)'{-v,--verbose}'[increase output verbosity]'
  369. # '--color=[specify when to use colors]:when:(always never auto)'
  370. # '*:example file:_files'
  371. #
  372. # Although there may appear to be six specs here, there are actually nine; we
  373. # use brace expansion to combine specs for options that go by multiple names,
  374. # like `-q` and `--quiet`. This is customary, and ties in with the fact that zsh
  375. # merges completion possibilities together when they have the same description.
  376. #
  377. # The first line defines the option `-h`/`--help`. With most tools, it isn't
  378. # useful to complete anything after `--help` because it effectively overrides
  379. # all others; the `(: * -)` at the beginning of the spec tells zsh not to
  380. # complete any other operands (`:` and `*`) or options (`-`) after this one has
  381. # been used. The `[...]` at the end associates a description with `-h`/`--help`;
  382. # as mentioned, zsh will see the identical descriptions and merge these options
  383. # together when offering completion possibilities.
  384. #
  385. # The next line defines `-q`/`--quiet`. Here we don't want to suppress further
  386. # completions entirely, but we don't want to offer `-q` if `--quiet` has been
  387. # given (since they do the same thing), nor do we want to offer `-v` (since it
  388. # doesn't make sense to be quiet and verbose at the same time). We don't need to
  389. # tell zsh not to offer `--quiet` a second time, since that's the default
  390. # behaviour, but since this line expands to two specs describing `-q` *and*
  391. # `--quiet` we do need to explicitly list all of them here.
  392. #
  393. # The next line defines a hidden option `--silent` — maybe it's a deprecated
  394. # synonym for `--quiet`. The leading `!` indicates that zsh shouldn't offer this
  395. # option during completion. The benefit of providing a spec for an option that
  396. # shouldn't be completed is that, if someone *does* use it, we can correctly
  397. # suppress completion of other options afterwards.
  398. #
  399. # The next line defines `-v`/`--verbose`; this works just like `-q`/`--quiet`.
  400. #
  401. # The next line defines `--color`. In this example, `--color` doesn't have a
  402. # corresponding short option, so we don't need to use brace expansion. Further,
  403. # there are no other options it's exclusive with (just itself), so we don't need
  404. # to define those at the beginning. However, it does take a mandatory argument.
  405. # The `=` at the end of `--color=` indicates that the argument may appear either
  406. # like `--color always` or like `--color=always`; this is how most GNU-style
  407. # command-line tools work. The corresponding short option would normally use `+`
  408. # — for example, `-c+` would allow either `-c always` or `-calways`. For this
  409. # option, the arguments are known ahead of time, so we can simply list them in
  410. # parentheses at the end (`when` is used as the description for the argument).
  411. #
  412. # The last line defines an operand (a non-option argument). In this example, the
  413. # operand can be used any number of times (the leading `*`), and it should be a
  414. # file path, so we tell zsh to call the `_files` function to complete it. The
  415. # `example file` in the middle is the description to use for this operand; we
  416. # could use a space instead to accept the default provided by `_files`.
  417. #
  418. # GROUPING ARGUMENT SPECIFICATIONS
  419. #
  420. # Newer versions of zsh support grouping argument specs together. All specs
  421. # following a `+` and then a group name are considered to be members of the
  422. # named group. Grouping is useful mostly for organisational purposes; it makes
  423. # the relationship between different options more obvious, and makes it easier
  424. # to specify exclusions.
  425. #
  426. # We could rewrite our example above using grouping as follows:
  427. #
  428. # '(: * -)'{-h,--help}'[display help information]'
  429. # '--color=[specify when to use colors]:when:(always never auto)'
  430. # '*:example file:_files'
  431. # + '(verbosity)'
  432. # {-q,--quiet}'[decrease output verbosity]'
  433. # '!--silent'
  434. # {-v,--verbose}'[increase output verbosity]'
  435. #
  436. # Here we take advantage of a useful feature of spec grouping — when the group
  437. # name is surrounded by parentheses, as in `(verbosity)`, it tells zsh that all
  438. # of the options in that group are exclusive with each other. As a result, we
  439. # don't need to manually list out the exclusions at the beginning of each
  440. # option.
  441. #
  442. # Groups can also be referred to by name in other argument specs; for example:
  443. #
  444. # '(xyz)--aaa' '*: :_files'
  445. # + xyz --xxx --yyy --zzz
  446. #
  447. # Here we use the group name `xyz` to tell zsh that `--xxx`, `--yyy`, and
  448. # `--zzz` are not to be completed after `--aaa`. This makes the exclusion list
  449. # much more compact and reusable.
  450. #
  451. # CONVENTIONS
  452. #
  453. # zsh completion functions generally adhere to the following conventions:
  454. #
  455. # * Use two spaces for indentation
  456. # * Combine specs for options with different names using brace expansion
  457. # * In combined specs, list the short option first (as in `{-a,--text}`)
  458. # * Use `+` or `=` as described above for options that take arguments
  459. # * Provide a description for all options, option-arguments, and operands
  460. # * Capitalise/punctuate argument descriptions as phrases, not complete
  461. # sentences — 'display help information', never 'Display help information.'
  462. # (but still capitalise acronyms and proper names)
  463. # * Write argument descriptions as verb phrases — 'display x', 'enable y',
  464. # 'use z'
  465. # * Word descriptions to make it clear when an option expects an argument;
  466. # usually this is done with the word 'specify', as in 'specify x' or
  467. # 'use specified x')
  468. # * Write argument descriptions as tersely as possible — for example, articles
  469. # like 'a' and 'the' should be omitted unless it would be confusing
  470. #
  471. # Other conventions currently used by this function:
  472. #
  473. # * Order argument specs alphabetically by group name, then option name
  474. # * Group options that are directly related, mutually exclusive, or frequently
  475. # referenced by other argument specs
  476. # * Use only characters in the set [a-z0-9_-] in group names
  477. # * Order exclusion lists as follows: short options, long options, groups
  478. # * Use American English in descriptions
  479. # * Use 'don't' in descriptions instead of 'do not'
  480. # * Word descriptions for related options as similarly as possible. For example,
  481. # `--foo[enable foo]` and `--no-foo[disable foo]`, or `--foo[use foo]` and
  482. # `--no-foo[don't use foo]`
  483. # * Word descriptions to make it clear when an option only makes sense with
  484. # another option, usually by adding '(with -x)' to the end
  485. # * Don't quote strings or variables unnecessarily. When quotes are required,
  486. # prefer single-quotes to double-quotes
  487. # * Prefix option specs with `$no` when the option serves only to negate the
  488. # behaviour of another option that must be provided explicitly by the user.
  489. # This prevents rarely used options from cluttering up the completion menu
  490. ################################################################################
  491. # ------------------------------------------------------------------------------
  492. # Copyright (c) 2011 Github zsh-users - http://github.com/zsh-users
  493. # All rights reserved.
  494. #
  495. # Redistribution and use in source and binary forms, with or without
  496. # modification, are permitted provided that the following conditions are met:
  497. # * Redistributions of source code must retain the above copyright
  498. # notice, this list of conditions and the following disclaimer.
  499. # * Redistributions in binary form must reproduce the above copyright
  500. # notice, this list of conditions and the following disclaimer in the
  501. # documentation and/or other materials provided with the distribution.
  502. # * Neither the name of the zsh-users nor the
  503. # names of its contributors may be used to endorse or promote products
  504. # derived from this software without specific prior written permission.
  505. #
  506. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  507. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  508. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  509. # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
  510. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  511. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  512. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  513. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  514. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  515. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  516. # ------------------------------------------------------------------------------
  517. # Description
  518. # -----------
  519. #
  520. # Completion script for ripgrep
  521. #
  522. # ------------------------------------------------------------------------------
  523. # Authors
  524. # -------
  525. #
  526. # * arcizan <ghostrevery@gmail.com>
  527. # * MaskRay <i@maskray.me>
  528. #
  529. # ------------------------------------------------------------------------------
  530. # Local Variables:
  531. # mode: shell-script
  532. # coding: utf-8-unix
  533. # indent-tabs-mode: nil
  534. # sh-indentation: 2
  535. # sh-basic-offset: 2
  536. # End:
  537. # vim: ft=zsh sw=2 ts=2 et