Bat: Formatting remains in the piped output under fish

Created on 7 Apr 2020  路  9Comments  路  Source: sharkdp/bat

What version of bat are you using?
0.13.0

Describe the bug you encountered:
When running under the fish shell, bat does not detect when its output is being piped. Running under bash on the same system works.

Describe what you expected to happen?
bat should detect when its output is being put through a pipe and strip formatting.

How did you install bat?
pacman -S bat


**$ uname -srm**
Linux 5.5.6-arch1-1 x86_64  

bat
---

**$ bat --version**
bat 0.13.0  

**$ env**

bat_config
----------

bat_wrapper
-----------

No wrapper script.

bat_wrapper_function
--------------------

No wrapper function.

tool
----

**$ less --version**
less 551 (PCRE regular expressions)  
question

All 9 comments

Perhaps I miss something - but for me it is important that bat does not strip formatting when output goes to a pipe. Example:

$ bat --color always --paging never sample.rs | ansi2html > sample.html

That is an option with --decorations always --color always, but the bat manpage itself specifies that this should not happen:

DESCRIPTION
       bat prints the syntax-highlighted content of a collection of FILEs to the terminal. If no FILE is specified, or when FILE is '-', it reads from standard input.

       bat supports a large number of programming and markup languages.  It also communicates with git(1) to show modifications with respect to the git index.  bat automatically pipes its output through a pager (by default: less).

       Whenever the output of bat goes to a non-interactive terminal, i.e. when the output is piped into another process or into a file, bat will act as a drop-in replacement for cat(1) and fall back to printing the plain file contents.

@markrawls Thank you for reporting this.

I can not reproduce this with fish 3.1.0:

image

I can't reproduce this on my machine either (fish 3.1.0, MacOS). I tried the following:

bat example.sh | cat

Does it work as expected with other shells on your machine?

You have my sincere apologies - it seems that at some point I specified a shell alias that adds --color always and forgot about that, which forced it

I suppose the real issue here is that under eterm-color in Emacs, bat will never have colored output.

Do you remember how you added the alias? The diagnostics script should have caught that when generating the output report.

In my ~/.config/fish/config.fish file I had alias cat='bat --color always'

@markrawls Thank you for the feedback. I assume this can be closed then.

@eth-p Maybe we should collection information about possible cat aliases as well?

@markrawls Thank you for the feedback. I assume this can be closed then.

@eth-p Maybe we should collection information about possible cat aliases as well?

That sounds like it would be a good idea. I'll do a bit of refactoring to make it possible to check any/all aliases from a list.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

niedzielski picture niedzielski  路  3Comments

antoinemadec picture antoinemadec  路  3Comments

issmirnov picture issmirnov  路  3Comments

rien333 picture rien333  路  3Comments

lilyball picture lilyball  路  3Comments