Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to enable --show-all output when output is redirected #1061

Closed
dandavison opened this issue Jun 16, 2020 · 4 comments · Fixed by #1066
Closed

Add ability to enable --show-all output when output is redirected #1061

dandavison opened this issue Jun 16, 2020 · 4 comments · Fixed by #1066
Labels
bug Something isn't working feature-request New feature or request

Comments

@dandavison
Copy link
Contributor

dandavison commented Jun 16, 2020

Hi, I occasionally find myself wanting to capture the (very nice and useful) --show-all output. For example, in order to compute a diff on the --show-all output itself. Currently, the only way I know how to do this is to print the --show-all output to the screen, select it with a mouse, and copy it into a text file. I understand the reason bat must, by default, only enable -A if stdout is attached to an interactive terminal. If not by default then perhaps what I'm requesting could be something like

bat --show-all=always

Thanks for all the work on bat!

@dandavison dandavison added the feature-request New feature or request label Jun 16, 2020
@dandavison
Copy link
Contributor Author

I understand the reason bat must, by default, only enable -A if stdout is attached to an interactive terminal.

Hm, or maybe I don't :) GNU cat allows -A to change the input even when the output is redirected. So perhaps bat could do this by default also? Or even should?

~ gcat --version
cat (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund and Richard M. Stallman.
~ echo hello | gcat | bat -A   
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ STDIN
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ hello␊
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
~ echo hello | gcat -A | bat -A
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ STDIN
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ hello$␊
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

@sharkdp
Copy link
Owner

sharkdp commented Jun 17, 2020

Thank you for the feedback and for reporting this!

I would actually consider this a bug. bat -A … should print the replacement characters, even if we are piping the output to a file / another program.

What you can do for now is to use --decorations=always and/or --color=always. You can combine that with --plain if you don't want to see the grid etc.

@sharkdp sharkdp added the bug Something isn't working label Jun 17, 2020
@sharkdp
Copy link
Owner

sharkdp commented Oct 2, 2020

Fixed in v0.16.0.

@arobase-che
Copy link

I didn't find a way to enable --show-all only if the output is interactive (stdout is a tty).

So here is a cat alias using bat:

function cat -d "Print a file nicely"
    if isatty stdout
        bat --show-all $argv
    else
        set -l catBin $(type --no-functions --path cat)
        $catBin $argv
    end
end

One can use bat -pp instead of cat:

function cat -d "Print a file nicely"
    if isatty stdout
        bat --show-all $argv
    else
        bat --style=plain --pager=never $argv
    end
end

Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature-request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants