--tabs 0 is realy 8
What version of bat are you using?
system
$ uname -srm Linux 5.5.13.a-1-hardened x86_64
$ lsb_release -a -e LSB Version: 1.4 -e Distributor ID: Arch -e Description: Arch Linux -e Release: rolling -e Codename: n/a
bat
$ bat --version bat 0.13.0
$ env
bat_config
bat_wrapper
No wrapper script.
bat_wrapper_function
Unable to determine if a wrapper function is set.
tool
$ less --version less 551 (PCRE regular expressions)
Describe the bug you encountered:
echo "1234567890\n\t1234567890\n\t\tasdf"|bat --tabs 0
prints
───────┬─────────────────────────────────────────────
│ STDIN
───────┼─────────────────────────────────────────────
1 │ 1234567890
2 │ 1234567890
3 │ asdf
───────┴─────────────────────────────────────────────
Describe what you expected to happen?
Given --tabs 0 the spaces in the output should be real tabs like:
───────┬─────────────────────────────────────────────
│ STDIN
───────┼─────────────────────────────────────────────
1 │ 1234567890
2 │ 1234567890
3 │ asdf
───────┴─────────────────────────────────────────────
How did you install bat?
pacman
Thank you for reporting this.
This is (arguably?) not a bug. When --tabs=0 is used, bat will leave tab characters untouched. The problem is that bat pipes its output into the pager less, which also does some sort of preprocessing. We can see this by disabling paging:
> echo "1234567890\n\t1234567890\n\t\tasdf" | bat --tabs=0 --paging=never
───────┬────────────────────────────────────────────
│ File: STDIN
───────┼────────────────────────────────────────────
1 │ 1234567890
2 │ 1234567890
3 │ asdf
───────┴────────────────────────────────────────────
The output now contains real tab characters.
Another way to achieve this is to use bats -p/--plain option twice. This sets --tabs=0 automatically and the second -p disables the pager:
> echo "1234567890\n\t1234567890\n\t\tasdf" | bat -pp
1234567890
1234567890
asdf
less has a -xn/--tabs=n option to control the tab width (which you can test by running echo … | bat --tabs=0 --pager="less -RF --tabs=4"), but unfortunately, there does not seem to be a way to tell less to leave tab characters untouched (https://unix.stackexchange.com/a/412283/229308). Otherwise, we could pass that option to less when --tabs=0 is used in bat.
@wommel Any feedback on this? I'd like to close this.
you are right.