Closed n1vux closed 7 years ago
Like the sound of this (once hacked ack1 to do something similar). Was working on a codebase with a lot of embedded SWIFT messages in test suite. Putting a line number and : straight before a line beginning ":20:" wasn't fun!
(Matt Thompson from ack-users here. Forgot about github issues...sorry!)
Huh. Just had to say I'd never heard of --initial-tab
. I'd always pipe'd the grep to awk. Even though I use ack almost exclusively, it still teaches me!
(re sorry, it is ok to raise a question on ack-users and let someone who knows the code write an issue only if there isn't an easy user-space answer ! )
AFAIK, --initial-tab
is a Gnu-ish extension, not Bell/POSIX, so not officially standard, so not surprised you hadn't seen it either -- only found it when i was looking to see if they had --no-line-number
(no!). ( I was looking because we do try to support grep flags as appropriate under the least-surprise principle. )
I am not terribly keen on putting a tab in, and would like the number right justified. My suggestion would be an option --number-format
Or is that too complex.
On 2 December 2014 at 16:59, Bill Ricker notifications@github.com wrote:
(re sorry, it is ok to raise a question on ack-users and let someone who knows the code write an issue only if there isn't an easy user-space answer ! )
AFAIK, --initial-tab is a Gnu-ish extension, not Bell/POSIX, so not officially standard, so not surprised you hadn't seen it either -- only found it when i was looking to see if they had --no-line-number (no!). ( I was looking because we do try to support grep flags as appropriate under the least-surprise principle. )
— Reply to this email directly or view it on GitHub https://github.com/petdance/ack2/issues/517#issuecomment-65264282.
Andrew - I'd like to be able to offer multiple options. Tab is one option, good for some uses - particularly if data contains tabs; suppress numbers is another. Enhancing line # formatting options would be a third. DWIM and TIMTOWTDI are our Perl mottos, so more is better.
In "%-5d%s ", are you suggesting the %s positions the (possibly colorized) line, or just the colon? I'd suggest the colon be a literal in "%-5d :" or "%8d\t" , if going sprintf route.
Formatting the number is adding much complexity.
We already have -o, --output which can do some primitive concatenation formating of literals with special variables $. $$& $' $_ $1 $2 etc. (With tabs, the deprecated $
$& $' would make for a KWIC index.)
But it doesn't allow calling sprintf().
Combining a sprintf-ish option for fancy formatting (right justified or zero filled) with a selection of matchvars without introducing a general turing machine security hole would be a problem. And then there's formatting filename:line when filename is on the line.
But allowing formatting of line # only if NOT adjusting rest of line seems stilted.
An option to force line numbers to zero fill to a (default) width of 8 might be easier than general case.
Perl code would be like ($line_no_width ? sprintf (q(%0*2$d), $line_no, $line_no_width) : $line_no )
(where $line_no_width is probably buried in the option hash ref), likely in the print_line_with_options() subroutine.
Closed and moved to wiki.
Per ack-users thread this day c/o Matt Thompson
Consider
--[no-?]line-number
and--initial-tab
for tabular neatness.I note that Gnu Grep has
-T
--initial-tab
to insert tab after Line Number to make alignments work but does not support the obvious--no-line-number
override (possibly as--no-filename
will do that in the only case that matters for them? ).(Right aligning line numbers could also tabularize, but too many edge cases.)