It would be nice to be able to use nl to number only non-blank lines with this command:
bat -p --color=always foo.c | nl -bt
However, empty lines in foo.c have escape sequences after passing through bat so that nl adds line numbers to seemingly blank lines.
$ bat --version
bat 0.10.0
@jzinn it works with --color=never or --color=auto.
If I understand correctly, you want to keep the syntax highlighting from bat while using nl for non-empty line numbering? I can confirm that it doesn't work as expected for that use case.
I'm not sure how @sharkdp would like to handle it, but I have a workaround with sed that you could use (probably as an alias) in the meantime:
Bash:
bat -pp --color=always [...] | sed $'s,^\(\x1b\\[[0-9;]*[a-zA-Z]\)*$,,' | nl -bt
Fish:
bat -pp --color=always [...] | sed (printf 's,^\(\x1b\\[[0-9;]*[a-zA-Z]\)*$,,') | nl -bt

To be honest, I don't think that this is something that we have to support by all means. If there is an easy solution for this, ok.
It鈥檚 marginal for sure, but worth making a issue, I thought, in case it鈥檚 an easy change.
This came about trying to highlight example code from Unix Network Programming, which does not number blank lines.
Closed in #766 by @mbarbar
This has been fixed in bat 0.13.
Most helpful comment
If I understand correctly, you want to keep the syntax highlighting from
batwhile usingnlfor non-empty line numbering? I can confirm that it doesn't work as expected for that use case.I'm not sure how @sharkdp would like to handle it, but I have a workaround with
sedthat you could use (probably as an alias) in the meantime:Bash:
Fish: