beyondgrep / ack3

ack is a grep-like search tool optimized for source code.
https://beyondgrep.com/
Other
706 stars 66 forks source link

Either don't strip a leading ./ from path name or provide an option to turn off stripping a leading ./ #263

Open xtaran opened 9 years ago

xtaran commented 9 years ago

The following has been reported in Debian as #798180 against ack 2.14 and I can still reproduce it with 2.15.01:

When ack prints filenames, it strips leading "./". This is harmful when you pass these filenames to another program, because a filename starting with "--" might be interpreted as an option:

$ ls
--interactive=.html
$ ack -f --html --print0 ./ | xargs -0 rm -f
rm: invalid argument ‘.html’ for ‘--interactive’
Valid arguments are:
 - ‘never’, ‘no’, ‘none’
 - ‘once’
 - ‘always’, ‘yes’
Try 'rm --help' for more information.

The given example can be solved with the GNU-ish -- as Debian ships GNU Coreutils' rm command:

$ ack -f --html --print0 ./ | xargs -0 rm -f --

But this may not work with other commands not providing a GNU-ish -- option or with a different rm implementation, e.g. a BSD-ish one.

I do see that stripping a leading ./ from a file's path is a neat feature for human use (I actually like it :-), so I understand if that's considered a feature. In that case, please provide an option to turn that feature off. So far (as of 2.15.01) I haven't found such an option in ack's man page.

jwilk commented 9 years ago

Original reporter here!

For simplicity, I'd suggest keeping ./ prefix iff --print0 is enabled: