From 3a744891242f9ead026221cc70c67bd994fe4fe5 Mon Sep 17 00:00:00 2001 From: Aaron Schrab Date: Wed, 22 Aug 2012 21:27:28 -0400 Subject: [PATCH 1/3] Fix binding options to their arguments for ack Add trailing +, -, and = as appropriate in call to _arguments to specify how arguments to options are handled. --- src/_ack | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/_ack b/src/_ack index 7feb69f..b2d11ab 100644 --- a/src/_ack +++ b/src/_ack @@ -59,9 +59,9 @@ _ack() { '(- 1 *)--help[print a short help statement]' \ '(- 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 --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' \ - '(-C --context -A --after-context -B --before-context)'{-C,--context}'[print N lines (default 2) of context around 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' \ + '(-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]' \ '(--nocolor)--color[highlight the matching text]' \ '(--color --color-filename --color-match --color-lineno)--nocolor[supress the color]' \ @@ -75,8 +75,8 @@ _ack() { '-f[only print the files that would be searched, without actually doing any searching]' \ '(--nofollow)--follow[follow symlinks]' \ '(--follow)--nofollow[don'\''t follow symlinks]' \ - '-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+[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' \ '(--nogroup)--group[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]' \ @@ -85,16 +85,16 @@ _ack() { '*--ignore-dir[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]' \ - '--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-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' \ - '(-m --max-count)'{-m,--max-count}'[stop reading a file after N matches]:number' \ + '--match=[specify the regular expression explicitly]:regex' \ + '(-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]' \ '(-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' \ - '--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' \ + '--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' \ '--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]' \ '(-Q --literal)'{-Q,--literal}'[quote all metacharacters in the pattern, it is treated as a literal]' \ @@ -103,7 +103,7 @@ _ack() { '--sort-files[sorts the found files lexically]' \ '--show-types[outputs the filetypes that ack associates with each file]' \ '--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-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]' \ From adf4e09e0a73343f42ac84ba79ac82f39c02ed17 Mon Sep 17 00:00:00 2001 From: Aaron Schrab Date: Wed, 22 Aug 2012 21:24:59 -0400 Subject: [PATCH 2/3] Ack _arguments call should use -s and -S Several single-character options may be specified in a single argument, so -s should be used. "--" specifies that there are no further options, so -S should be used. --- src/_ack | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_ack b/src/_ack index b2d11ab..71fe6c6 100644 --- a/src/_ack +++ b/src/_ack @@ -54,7 +54,7 @@ _ack() { [[ $#_ack_raw_types -gt 0 ]] && _store_cache "ack-grep" _ack_raw_types fi - _arguments -C \ + _arguments -C -s -S \ '(- 1 *)--version[display version and copyright information]' \ '(- 1 *)--help[print a short help statement]' \ '(- 1 *)--man[print the manual page]' \ From 7b12d0beaa9a0c62decb46570b8e5f870a699a19 Mon Sep 17 00:00:00 2001 From: Aaron Schrab Date: Wed, 22 Aug 2012 21:10:52 -0400 Subject: [PATCH 3/3] Ack first argument is file if --match used Complete all non-option arguments as file names if the --match argument is present. --- src/_ack | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/_ack b/src/_ack index 71fe6c6..e669cd8 100644 --- a/src/_ack +++ b/src/_ack @@ -43,7 +43,9 @@ _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 [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _ack_types_caching_policy @@ -54,7 +56,7 @@ _ack() { [[ $#_ack_raw_types -gt 0 ]] && _store_cache "ack-grep" _ack_raw_types fi - _arguments -C -s -S \ + _arguments -C -s -S -n \ '(- 1 *)--version[display version and copyright information]' \ '(- 1 *)--help[print a short help statement]' \ '(- 1 *)--man[print the manual page]' \ @@ -111,13 +113,19 @@ _ack() { '(-w --word-regexp)'{-w,--word-regexp}'[force the given pattern to match only whole words]' \ '-1[stops after reporting first match of any kind]' \ {'--','--no'}${_ack_raw_types/ ##/\[}']' \ - '1: :->patterns' \ - '*: :_files' \ + '*: :->args' \ && ret=0 case $state in - patterns) - _message -e patterns 'pattern' && ret=0 + args) + 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) local colors; colors=(