Merge pull request #94 from aschrab/ack

Improvements to ack completion
This commit is contained in:
Mario Fernández 2012-08-23 00:35:31 -07:00
commit ebd708b7a4
1 changed files with 25 additions and 17 deletions

View File

@ -43,7 +43,9 @@
_ack() { _ack() {
local curcontext="$curcontext" state line cmds update_policy ret=1 local context curcontext="$curcontext" state line cmds update_policy ret=1
integer NORMARG
typeset -A opt_args
zstyle -s ":completion:${curcontext}:" cache-policy update_policy zstyle -s ":completion:${curcontext}:" cache-policy update_policy
[[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _ack_types_caching_policy [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _ack_types_caching_policy
@ -54,14 +56,14 @@ _ack() {
[[ $#_ack_raw_types -gt 0 ]] && _store_cache "ack-grep" _ack_raw_types [[ $#_ack_raw_types -gt 0 ]] && _store_cache "ack-grep" _ack_raw_types
fi fi
_arguments -C \ _arguments -C -s -S -n \
'(- 1 *)--version[display version and copyright information]' \ '(- 1 *)--version[display version and copyright information]' \
'(- 1 *)--help[print a short help statement]' \ '(- 1 *)--help[print a short help statement]' \
'(- 1 *)--man[print the manual page]' \ '(- 1 *)--man[print the manual page]' \
'(-a --all -u --unrestricted)'{-a,--all}'[operate on all files, regardless of type (but still skip directories like blib, CVS, etc.)]' \ '(-a --all -u --unrestricted)'{-a,--all}'[operate on all files, regardless of type (but still skip directories like blib, CVS, etc.)]' \
'(-A --after-context -C --context)'{-A,--after-context}'[print N lines of trailing context after matching lines]:number' \ '(-A --after-context -C --context)'{-A+,--after-context=}'[print N lines of trailing context after matching lines]:number' \
'(-B --before-context -C --context)'{-B,--before-context}'[print N lines of leading context before matching lines]:number' \ '(-B --before-context -C --context)'{-B+,--before-context=}'[print N lines of leading context before matching lines]:number' \
'(-C --context -A --after-context -B --before-context)'{-C,--context}'[print N lines (default 2) of context around matching lines]:number' \ '(-C --context -A --after-context -B --before-context)'{-C-,--context=}'[print N lines (default 2) of context around matching lines]:number' \
'(-c --count)'{-c,--count}'[suppress normal output; instead print a count of matching lines for each input file]' \ '(-c --count)'{-c,--count}'[suppress normal output; instead print a count of matching lines for each input file]' \
'(--nocolor)--color[highlight the matching text]' \ '(--nocolor)--color[highlight the matching text]' \
'(--color --color-filename --color-match --color-lineno)--nocolor[supress the color]' \ '(--color --color-filename --color-match --color-lineno)--nocolor[supress the color]' \
@ -75,8 +77,8 @@ _ack() {
'-f[only print the files that would be searched, without actually doing any searching]' \ '-f[only print the files that would be searched, without actually doing any searching]' \
'(--nofollow)--follow[follow symlinks]' \ '(--nofollow)--follow[follow symlinks]' \
'(--follow)--nofollow[don'\''t follow symlinks]' \ '(--follow)--nofollow[don'\''t follow symlinks]' \
'-G[only paths matching the given regex are included in the search]:regex' \ '-G+[only paths matching the given regex are included in the search]:regex' \
'-g[print files where the relative path + filename matches the given regex]:regex' \ '-g+[print files where the relative path + filename matches the given regex]:regex' \
'(--nogroup)--group[group matches by file name]' \ '(--nogroup)--group[group matches by file name]' \
'(--group)--nogroup[do not group matches by file name]' \ '(--group)--nogroup[do not group matches by file name]' \
'(-H --with-filename -h --no-filename)'{-H,--with-filename}'[print the filename for each match]' \ '(-H --with-filename -h --no-filename)'{-H,--with-filename}'[print the filename for each match]' \
@ -85,16 +87,16 @@ _ack() {
'*--ignore-dir[ignore directory]:directory:_files -/' \ '*--ignore-dir[ignore directory]:directory:_files -/' \
'*--noignore-dir[don'\''t ignore directory]:directory:_files -/' \ '*--noignore-dir[don'\''t ignore directory]:directory:_files -/' \
'--invert-file-match[print/search handle files that do not match -g/-G]' \ '--invert-file-match[print/search handle files that do not match -g/-G]' \
'--line[only print given line of each file]:number' \ '--line=[only print given line of each file]:number' \
'(-l --files-with-matches -L --files-without-matches)'{-l,--files-with-matches}'[only print the filenames of matching files, instead of the matching text]' \ '(-l --files-with-matches -L --files-without-matches)'{-l,--files-with-matches}'[only print the filenames of matching files, instead of the matching text]' \
'(-L --files-without-matches -l --files-with-matches)'{-L,--files-without-matches}'[only print the filenames of files that do NOT match]' \ '(-L --files-without-matches -l --files-with-matches)'{-L,--files-without-matches}'[only print the filenames of files that do NOT match]' \
'--match[specify the regular expression explicitly]:regex' \ '--match=[specify the regular expression explicitly]:regex' \
'(-m --max-count)'{-m,--max-count}'[stop reading a file after N matches]:number' \ '(-m --max-count)'{-m+,--max-count=}'[stop reading a file after N matches]:number' \
'(-r -R --recurse -n --no-recurse)'{-r,-R,--recurse}'[recurse into sub-directories]' \ '(-r -R --recurse -n --no-recurse)'{-r,-R,--recurse}'[recurse into sub-directories]' \
'(-n --no-recurse -r -R --recurse)'{-n,--no-recurse}'[no descending into subdirectories]' \ '(-n --no-recurse -r -R --recurse)'{-n,--no-recurse}'[no descending into subdirectories]' \
'-o[show only the part of each line matching PATTERN (turns off text highlighting)]:pattern' \ '-o[show only the part of each line matching PATTERN (turns off text highlighting)]:pattern' \
'--output[output the evaluation of expr for each line (turns off text highlighting)]:expression' \ '--output=[output the evaluation of expr for each line (turns off text highlighting)]:expression' \
'--pager[direct ack'\''s output through program]:pager program:_command_names' \ '--pager=[direct ack'\''s output through program]:pager program:_command_names' \
'--passthru[prints all lines, whether or not they match the expression]' \ '--passthru[prints all lines, whether or not they match the expression]' \
'--print0[the filenames are output separated with a null byte instead of the usual newline]' \ '--print0[the filenames are output separated with a null byte instead of the usual newline]' \
'(-Q --literal)'{-Q,--literal}'[quote all metacharacters in the pattern, it is treated as a literal]' \ '(-Q --literal)'{-Q,--literal}'[quote all metacharacters in the pattern, it is treated as a literal]' \
@ -103,7 +105,7 @@ _ack() {
'--sort-files[sorts the found files lexically]' \ '--sort-files[sorts the found files lexically]' \
'--show-types[outputs the filetypes that ack associates with each file]' \ '--show-types[outputs the filetypes that ack associates with each file]' \
'--thpppt[display the all-important Bill The Cat logo]' \ '--thpppt[display the all-important Bill The Cat logo]' \
'*--type[specify the types of files to include or exclude from a search]:type:->types' \ '*--type=[specify the types of files to include or exclude from a search]:type:->types' \
'*--type-add[files with the given extensions are recognized as being of the given type]:type-def:->type-defs' \ '*--type-add[files with the given extensions are recognized as being of the given type]:type-def:->type-defs' \
'*--type-set[files with the given extensions are recognized as being of the given type]:type-def:->type-defs' \ '*--type-set[files with the given extensions are recognized as being of the given type]:type-def:->type-defs' \
'(-u --unrestricted -a --all)'{-u,--unrestricted}'[all files and directories (including blib/, core.*, ...) are searched, nothing is skipped]' \ '(-u --unrestricted -a --all)'{-u,--unrestricted}'[all files and directories (including blib/, core.*, ...) are searched, nothing is skipped]' \
@ -111,13 +113,19 @@ _ack() {
'(-w --word-regexp)'{-w,--word-regexp}'[force the given pattern to match only whole words]' \ '(-w --word-regexp)'{-w,--word-regexp}'[force the given pattern to match only whole words]' \
'-1[stops after reporting first match of any kind]' \ '-1[stops after reporting first match of any kind]' \
{'--','--no'}${_ack_raw_types/ ##/\[}']' \ {'--','--no'}${_ack_raw_types/ ##/\[}']' \
'1: :->patterns' \ '*: :->args' \
'*: :_files' \
&& ret=0 && ret=0
case $state in case $state in
patterns) args)
_message -e patterns 'pattern' && ret=0 if [[ CURRENT -eq NORMARG && ${+opt_args[--match]} -eq 0 ]]
then
# If the current argument is the first non-option argument
# and --match isn't present then a pattern is expected
_message -e patterns 'pattern' && ret=0
else
_files
fi
;; ;;
colors) colors)
local colors; colors=( local colors; colors=(