Bat: Case insensitive search

Created on 5 Aug 2020  Â·  11Comments  Â·  Source: sharkdp/bat

I've added a pager to my command. So is there any option to search any string case-insensitive?

question

Most helpful comment

Here's a quick screencast.
https://www.dropbox.com/s/8jqgwbbe9fow84y/bat_case_insensitive_not_working.webm?dl=0

@rajeshisnepali I think ignore case mode only effected when searching with pure lower case string. If the searching string contains A single uppercase character, ignore case mode won't work anymore.
These two pictures below are searching in ignore case mode.
image
image

All 11 comments

Then it really depends on your pager. See -i and -I options in man 1 less for less (also mind that less in turn depends on your system regex library - use ldd $(which less) to check - usually should be pcre standard perl regex). Otherwise you should search the docs of your pager.

I think what @rajeshisnepali wanted is more like less -i. For exmaple, cat somefile.txt | less -i.
bat can't do this trick.

-- update --
But you can bat somefile.txt and type -i to enable ignore case.
image

@archongum bat somefile.txt and typing -i didn't work for me.

Here's a quick screencast.
https://www.dropbox.com/s/8jqgwbbe9fow84y/bat_case_insensitive_not_working.webm?dl=0

Here's a quick screencast.
https://www.dropbox.com/s/8jqgwbbe9fow84y/bat_case_insensitive_not_working.webm?dl=0

@rajeshisnepali I think ignore case mode only effected when searching with pure lower case string. If the searching string contains A single uppercase character, ignore case mode won't work anymore.
These two pictures below are searching in ignore case mode.
image
image

You can also use the --pager option in the config file to always pass -i to less (see README for details).

Oh yes, for bat 0.15.4 and newer I believe the default pager is set as of less. I've aliased both cat & less to bat to perform accordingly.

I'm just trying this now (on Arch); with export PAGER="/usr/bin/less -RFI" then bat /some/file, it doesn't work, but if I do bat --pager "less -RFI" /some/file it does work. I'm quite confused by this.

PAGER will be overwritten by BAT_PAGER (have you set this?), which will be overwritten by --pager=… settings in the config file or the command line.

I don't have a bat config nor BAT_PAGER set, but setting BAT_PAGER resolved this, thanks :)

I don't have a bat config nor BAT_PAGER set, but setting BAT_PAGER resolved this, thanks :)

Oh - right. If we detect less in PAGER, we actually overwrite the command line options (to make sure -R is included). So using BAT_PAGER or the config file is the only option here.

It would be great if someone could add this to the README.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sharkdp picture sharkdp  Â·  3Comments

adamtabrams picture adamtabrams  Â·  3Comments

issmirnov picture issmirnov  Â·  3Comments

antoinemadec picture antoinemadec  Â·  3Comments

tomgoren picture tomgoren  Â·  3Comments