Bat: Highlight only a portion of a line

Created on 25 Sep 2019  路  4Comments  路  Source: sharkdp/bat

Bat can highlight individual lines using the -H argument.

I have a use case for which I would like to highlight only a portion of a line, say from character 10 to 20. How should I do this? Is it a desirable feature? The command line option could be something like -H $LINE:10:20.

feature-request

Most helpful comment

I made a table with possible scenarios with the corresponding syntax
(lines are uppercase starting with L, characters are lowercase starting with c, F/f stands for "from", T/t stands for "to")

Range|One line|Line range|Character range|Multiline character range
:-:|:-:|:-:|:-:|:-:
Start|-|LF:|L.cf:|LF.cf:
End|-|:LT|L.:.ct|:LT.ct
Both|L|LF:LT|L.cf:.ct|LF.cf:LT.ct

  • : means "range" - it separates start from end
  • . means "char" - it separates line number from character number

Is that good or it needs changes?

All 4 comments

I don't think --highlight-line $LINE:$COL_START:$COL_END would be too great of an idea, to be honest. It's using a similar syntax to --line-range, but has a completely different meaning. Using a colon would probably be fine as long as it's clear that it's not a line range, but a character range (maybe 372.10:20?).

Other ideas:

  • 10:20@$LINE
  • 10-20@$LINE
  • 10.20@$LINE
  • $LINE/10.20
  • $LINE/10-20
  • $LINEc5:10 (e.g. 372c5:10)
  • $LINE_5:10
  • $LINE.5:10

Note: We can't use commas because of the changes eventually being introduced with #654.

I was thinking about opening a PR for highlighting ranges as well, so I'd agree with you @eth-p on not using : as a separator. (My personnal favourite would be $LINE.10:20)

Range highlighting would be -H 1 -H 3:7, which could already be done in a less elegant fashion: -H 1 -H 3 -H 4 -H 5 -H 6 -H 7.

I made a table with possible scenarios with the corresponding syntax
(lines are uppercase starting with L, characters are lowercase starting with c, F/f stands for "from", T/t stands for "to")

Range|One line|Line range|Character range|Multiline character range
:-:|:-:|:-:|:-:|:-:
Start|-|LF:|L.cf:|LF.cf:
End|-|:LT|L.:.ct|:LT.ct
Both|L|LF:LT|L.cf:.ct|LF.cf:LT.ct

  • : means "range" - it separates start from end
  • . means "char" - it separates line number from character number

Is that good or it needs changes?

Edited it a bit, now column numbers must be preceded with .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

issmirnov picture issmirnov  路  3Comments

HakubJozak picture HakubJozak  路  3Comments

tomgoren picture tomgoren  路  3Comments

tbsvttr picture tbsvttr  路  3Comments

samuelcolvin picture samuelcolvin  路  3Comments