_ripgrep 28 KB

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