_ripgrep 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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. '--trace[show more verbose debug messages]'
  245. '--dfa-size-limit=[specify upper size limit of generated DFA]:DFA size (bytes)'
  246. "(1 stats)--files[show each file that would be searched (but don't search)]"
  247. '*--ignore-file=[specify additional ignore file]:ignore file:_files'
  248. '(-v --invert-match)'{-v,--invert-match}'[invert matching]'
  249. '(-M --max-columns)'{-M+,--max-columns=}'[specify max length of lines to print]:number of bytes'
  250. '(-m --max-count)'{-m+,--max-count=}'[specify max number of matches per file]:number of matches'
  251. '--max-filesize=[specify size above which files should be ignored]:file size (bytes)'
  252. "--no-config[don't load configuration files]"
  253. '(-0 --null)'{-0,--null}'[print NUL byte after file names]'
  254. '--path-separator=[specify path separator to use when printing file names]:separator'
  255. '(-q --quiet)'{-q,--quiet}'[suppress normal output]'
  256. '--regex-size-limit=[specify upper size limit of compiled regex]:regex size (bytes)'
  257. '*'{-u,--unrestricted}'[reduce level of "smart" searching]'
  258. + operand # Operands
  259. '(--files --type-list file regexp)1: :_guard "^-*" pattern'
  260. '(--type-list)*: :_files'
  261. )
  262. # This is used with test-complete to verify that there are no options
  263. # listed in the help output that aren't also defined here
  264. [[ $_RG_COMPLETE_LIST_ARGS == (1|t*|y*) ]] && {
  265. print -rl - $args
  266. return 0
  267. }
  268. # Strip out argument groups where unsupported (see above)
  269. [[ $ZSH_VERSION == (4|5.<0-3>)(.*)# ]] &&
  270. args=( ${(@)args:#(#i)(+|[a-z0-9][a-z0-9_-]#|\([a-z0-9][a-z0-9_-]#\))} )
  271. _arguments -C -s -S : $args && ret=0
  272. case $state in
  273. colorspec)
  274. if [[ ${IPREFIX#--*=}$PREFIX == [^:]# ]]; then
  275. suf=( -qS: )
  276. tmp=(
  277. 'column:specify coloring for column numbers'
  278. 'line:specify coloring for line numbers'
  279. 'match:specify coloring for match text'
  280. 'path:specify coloring for file names'
  281. )
  282. descr='color/style type'
  283. elif [[ ${IPREFIX#--*=}$PREFIX == (column|line|match|path):[^:]# ]]; then
  284. suf=( -qS: )
  285. tmp=(
  286. 'none:clear color/style for type'
  287. 'bg:specify background color'
  288. 'fg:specify foreground color'
  289. 'style:specify text style'
  290. )
  291. descr='color/style attribute'
  292. elif [[ ${IPREFIX#--*=}$PREFIX == [^:]##:(bg|fg):[^:]# ]]; then
  293. tmp=( black blue green red cyan magenta yellow white )
  294. descr='color name or r,g,b'
  295. elif [[ ${IPREFIX#--*=}$PREFIX == [^:]##:style:[^:]# ]]; then
  296. tmp=( {,no}bold {,no}intense {,no}underline )
  297. descr='style name'
  298. else
  299. _message -e colorspec 'no more arguments'
  300. fi
  301. (( $#tmp )) && {
  302. compset -P '*:'
  303. _describe -t colorspec $descr tmp $suf && ret=0
  304. }
  305. ;;
  306. typespec)
  307. if compset -P '[^:]##:include:'; then
  308. _sequence -s , _rg_types && ret=0
  309. # @todo This bit in particular could be better, but it's a little
  310. # complex, and attempting to solve it seems to run us up against a crash
  311. # bug — zsh # 40362
  312. elif compset -P '[^:]##:'; then
  313. _message 'glob or include directive' && ret=1
  314. elif [[ ! -prefix *:* ]]; then
  315. _rg_types -qS : && ret=0
  316. fi
  317. ;;
  318. esac
  319. return ret
  320. }
  321. # Complete encodings
  322. _rg_encodings() {
  323. local -a expl
  324. local -aU _encodings
  325. # This is impossible to read, but these encodings rarely if ever change, so it
  326. # probably doesn't matter. They are derived from the list given here:
  327. # https://encoding.spec.whatwg.org/#concept-encoding-get
  328. _encodings=(
  329. {{,us-}ascii,arabic,chinese,cyrillic,greek{,8},hebrew,korean}
  330. logical visual mac {,cs}macintosh x-mac-{cyrillic,roman,ukrainian}
  331. 866 ibm{819,866} csibm866
  332. big5{,-hkscs} {cn-,cs}big5 x-x-big5
  333. cp{819,866,125{0..8}} x-cp125{0..8}
  334. csiso2022{jp,kr} csiso8859{6,8}{e,i}
  335. csisolatin{{1..6},9} csisolatin{arabic,cyrillic,greek,hebrew}
  336. ecma-{114,118} asmo-708 elot_928 sun_eu_greek
  337. euc-{jp,kr} x-euc-jp cseuckr cseucpkdfmtjapanese
  338. {,x-}gbk csiso58gb231280 gb18030 {,cs}gb2312 gb_2312{,-80} hz-gb-2312
  339. iso-2022-{cn,cn-ext,jp,kr}
  340. iso8859{,-}{{1..11},13,14,15}
  341. iso-8859-{{1..11},{6,8}-{e,i},13,14,15,16} iso_8859-{{1..9},15}
  342. iso_8859-{1,2,6,7}:1987 iso_8859-{3,4,5,8}:1988 iso_8859-9:1989
  343. iso-ir-{58,100,101,109,110,126,127,138,144,148,149,157}
  344. koi{,8,8-r,8-ru,8-u,8_r} cskoi8r
  345. ks_c_5601-{1987,1989} ksc{,_}5691 csksc56011987
  346. latin{1..6} l{{1..6},9}
  347. shift{-,_}jis csshiftjis {,x-}sjis ms_kanji ms932
  348. utf{,-}8 utf-16{,be,le} unicode-1-1-utf-8
  349. windows-{31j,874,949,125{0..8}} dos-874 tis-620 ansi_x3.4-1968
  350. x-user-defined auto none
  351. )
  352. _wanted encodings expl encoding compadd -a "$@" - _encodings
  353. }
  354. # Complete file types
  355. _rg_types() {
  356. local -a expl
  357. local -aU _types
  358. _types=( ${(@)${(f)"$( _call_program types rg --type-list )"}%%:*} )
  359. _wanted types expl 'file type' compadd -a "$@" - _types
  360. }
  361. _rg "$@"
  362. ################################################################################
  363. # ZSH COMPLETION REFERENCE
  364. #
  365. # For the convenience of developers who aren't especially familiar with zsh
  366. # completion functions, a brief reference guide follows. This is in no way
  367. # comprehensive; it covers just enough of the basic structure, syntax, and
  368. # conventions to help someone make simple changes like adding new options. For
  369. # more complete documentation regarding zsh completion functions, please see the
  370. # following:
  371. #
  372. # * http://zsh.sourceforge.net/Doc/Release/Completion-System.html
  373. # * https://github.com/zsh-users/zsh/blob/master/Etc/completion-style-guide
  374. #
  375. # OVERVIEW
  376. #
  377. # Most zsh completion functions are defined in terms of `_arguments`, which is a
  378. # shell function that takes a series of argument specifications. The specs for
  379. # `rg` are stored in an array, which is common for more complex functions; the
  380. # elements of the array are passed to `_arguments` on invocation.
  381. #
  382. # ARGUMENT-SPECIFICATION SYNTAX
  383. #
  384. # The following is a contrived example of the argument specs for a simple tool:
  385. #
  386. # '(: * -)'{-h,--help}'[display help information]'
  387. # '(-q -v --quiet --verbose)'{-q,--quiet}'[decrease output verbosity]'
  388. # '!(-q -v --quiet --verbose)--silent'
  389. # '(-q -v --quiet --verbose)'{-v,--verbose}'[increase output verbosity]'
  390. # '--color=[specify when to use colors]:when:(always never auto)'
  391. # '*:example file:_files'
  392. #
  393. # Although there may appear to be six specs here, there are actually nine; we
  394. # use brace expansion to combine specs for options that go by multiple names,
  395. # like `-q` and `--quiet`. This is customary, and ties in with the fact that zsh
  396. # merges completion possibilities together when they have the same description.
  397. #
  398. # The first line defines the option `-h`/`--help`. With most tools, it isn't
  399. # useful to complete anything after `--help` because it effectively overrides
  400. # all others; the `(: * -)` at the beginning of the spec tells zsh not to
  401. # complete any other operands (`:` and `*`) or options (`-`) after this one has
  402. # been used. The `[...]` at the end associates a description with `-h`/`--help`;
  403. # as mentioned, zsh will see the identical descriptions and merge these options
  404. # together when offering completion possibilities.
  405. #
  406. # The next line defines `-q`/`--quiet`. Here we don't want to suppress further
  407. # completions entirely, but we don't want to offer `-q` if `--quiet` has been
  408. # given (since they do the same thing), nor do we want to offer `-v` (since it
  409. # doesn't make sense to be quiet and verbose at the same time). We don't need to
  410. # tell zsh not to offer `--quiet` a second time, since that's the default
  411. # behaviour, but since this line expands to two specs describing `-q` *and*
  412. # `--quiet` we do need to explicitly list all of them here.
  413. #
  414. # The next line defines a hidden option `--silent` — maybe it's a deprecated
  415. # synonym for `--quiet`. The leading `!` indicates that zsh shouldn't offer this
  416. # option during completion. The benefit of providing a spec for an option that
  417. # shouldn't be completed is that, if someone *does* use it, we can correctly
  418. # suppress completion of other options afterwards.
  419. #
  420. # The next line defines `-v`/`--verbose`; this works just like `-q`/`--quiet`.
  421. #
  422. # The next line defines `--color`. In this example, `--color` doesn't have a
  423. # corresponding short option, so we don't need to use brace expansion. Further,
  424. # there are no other options it's exclusive with (just itself), so we don't need
  425. # to define those at the beginning. However, it does take a mandatory argument.
  426. # The `=` at the end of `--color=` indicates that the argument may appear either
  427. # like `--color always` or like `--color=always`; this is how most GNU-style
  428. # command-line tools work. The corresponding short option would normally use `+`
  429. # — for example, `-c+` would allow either `-c always` or `-calways`. For this
  430. # option, the arguments are known ahead of time, so we can simply list them in
  431. # parentheses at the end (`when` is used as the description for the argument).
  432. #
  433. # The last line defines an operand (a non-option argument). In this example, the
  434. # operand can be used any number of times (the leading `*`), and it should be a
  435. # file path, so we tell zsh to call the `_files` function to complete it. The
  436. # `example file` in the middle is the description to use for this operand; we
  437. # could use a space instead to accept the default provided by `_files`.
  438. #
  439. # GROUPING ARGUMENT SPECIFICATIONS
  440. #
  441. # Newer versions of zsh support grouping argument specs together. All specs
  442. # following a `+` and then a group name are considered to be members of the
  443. # named group. Grouping is useful mostly for organisational purposes; it makes
  444. # the relationship between different options more obvious, and makes it easier
  445. # to specify exclusions.
  446. #
  447. # We could rewrite our example above using grouping as follows:
  448. #
  449. # '(: * -)'{-h,--help}'[display help information]'
  450. # '--color=[specify when to use colors]:when:(always never auto)'
  451. # '*:example file:_files'
  452. # + '(verbosity)'
  453. # {-q,--quiet}'[decrease output verbosity]'
  454. # '!--silent'
  455. # {-v,--verbose}'[increase output verbosity]'
  456. #
  457. # Here we take advantage of a useful feature of spec grouping — when the group
  458. # name is surrounded by parentheses, as in `(verbosity)`, it tells zsh that all
  459. # of the options in that group are exclusive with each other. As a result, we
  460. # don't need to manually list out the exclusions at the beginning of each
  461. # option.
  462. #
  463. # Groups can also be referred to by name in other argument specs; for example:
  464. #
  465. # '(xyz)--aaa' '*: :_files'
  466. # + xyz --xxx --yyy --zzz
  467. #
  468. # Here we use the group name `xyz` to tell zsh that `--xxx`, `--yyy`, and
  469. # `--zzz` are not to be completed after `--aaa`. This makes the exclusion list
  470. # much more compact and reusable.
  471. #
  472. # CONVENTIONS
  473. #
  474. # zsh completion functions generally adhere to the following conventions:
  475. #
  476. # * Use two spaces for indentation
  477. # * Combine specs for options with different names using brace expansion
  478. # * In combined specs, list the short option first (as in `{-a,--text}`)
  479. # * Use `+` or `=` as described above for options that take arguments
  480. # * Provide a description for all options, option-arguments, and operands
  481. # * Capitalise/punctuate argument descriptions as phrases, not complete
  482. # sentences — 'display help information', never 'Display help information.'
  483. # (but still capitalise acronyms and proper names)
  484. # * Write argument descriptions as verb phrases — 'display x', 'enable y',
  485. # 'use z'
  486. # * Word descriptions to make it clear when an option expects an argument;
  487. # usually this is done with the word 'specify', as in 'specify x' or
  488. # 'use specified x')
  489. # * Write argument descriptions as tersely as possible — for example, articles
  490. # like 'a' and 'the' should be omitted unless it would be confusing
  491. #
  492. # Other conventions currently used by this function:
  493. #
  494. # * Order argument specs alphabetically by group name, then option name
  495. # * Group options that are directly related, mutually exclusive, or frequently
  496. # referenced by other argument specs
  497. # * Use only characters in the set [a-z0-9_-] in group names
  498. # * Order exclusion lists as follows: short options, long options, groups
  499. # * Use American English in descriptions
  500. # * Use 'don't' in descriptions instead of 'do not'
  501. # * Word descriptions for related options as similarly as possible. For example,
  502. # `--foo[enable foo]` and `--no-foo[disable foo]`, or `--foo[use foo]` and
  503. # `--no-foo[don't use foo]`
  504. # * Word descriptions to make it clear when an option only makes sense with
  505. # another option, usually by adding '(with -x)' to the end
  506. # * Don't quote strings or variables unnecessarily. When quotes are required,
  507. # prefer single-quotes to double-quotes
  508. # * Prefix option specs with `$no` when the option serves only to negate the
  509. # behaviour of another option that must be provided explicitly by the user.
  510. # This prevents rarely used options from cluttering up the completion menu
  511. ################################################################################
  512. # ------------------------------------------------------------------------------
  513. # Copyright (c) 2011 Github zsh-users - http://github.com/zsh-users
  514. # All rights reserved.
  515. #
  516. # Redistribution and use in source and binary forms, with or without
  517. # modification, are permitted provided that the following conditions are met:
  518. # * Redistributions of source code must retain the above copyright
  519. # notice, this list of conditions and the following disclaimer.
  520. # * Redistributions in binary form must reproduce the above copyright
  521. # notice, this list of conditions and the following disclaimer in the
  522. # documentation and/or other materials provided with the distribution.
  523. # * Neither the name of the zsh-users nor the
  524. # names of its contributors may be used to endorse or promote products
  525. # derived from this software without specific prior written permission.
  526. #
  527. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  528. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  529. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  530. # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
  531. # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  532. # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  533. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  534. # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  535. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  536. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  537. # ------------------------------------------------------------------------------
  538. # Description
  539. # -----------
  540. #
  541. # Completion script for ripgrep
  542. #
  543. # ------------------------------------------------------------------------------
  544. # Authors
  545. # -------
  546. #
  547. # * arcizan <ghostrevery@gmail.com>
  548. # * MaskRay <i@maskray.me>
  549. #
  550. # ------------------------------------------------------------------------------
  551. # Local Variables:
  552. # mode: shell-script
  553. # coding: utf-8-unix
  554. # indent-tabs-mode: nil
  555. # sh-indentation: 2
  556. # sh-basic-offset: 2
  557. # End:
  558. # vim: ft=zsh sw=2 ts=2 et