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

providing non-interactive mode #539

Closed
jjangga0214 opened this issue Apr 8, 2019 · 7 comments
Closed

providing non-interactive mode #539

jjangga0214 opened this issue Apr 8, 2019 · 7 comments
Labels
question Further information is requested

Comments

@jjangga0214
Copy link

jjangga0214 commented Apr 8, 2019

Hi,

bat enters interactive mode though I didn't pipeline it to less.
I wonder if it's intended and there's an option or workaround to just print the content.

Thanks.

@sharkdp
Copy link
Owner

sharkdp commented Apr 8, 2019

bat enters interactive mode though I didn't pipeline it to less.

Yes, that is the intended behavior. Interactive mode means: the output goes to an interactive terminal. That is usually the case if the output is not piped anywhere else.

If you want the plain file contents, use --plain. Or pipe the output to a file or another program.

@sharkdp sharkdp added the question Further information is requested label Apr 8, 2019
@jjangga0214
Copy link
Author

jjangga0214 commented Apr 9, 2019

Thanks @sharkdp, but..

what I've tried to find is a way or an option to just print the whole file content non-interactively with styles and decorations such as line numbers, filename, and colors, which is not achieved by --plain option.

On my computer (zsh v5.7.1, kali-rolling (debian stretch)), bat -p <file> removes decorations, but still enters into interactive mode (If you meant -p prints plain content non-interractively, is this behavior a bug only shown on my(or other rare) system?).

If I pipe the output, then the file contents is just printed non-interatively. However, decorations and style are not preserved, which is not what I want.

Is there a way? If it's not just implemented, do you think it can be good to be? (for me, I feel definitely "yes")

@sharkdp
Copy link
Owner

sharkdp commented Apr 9, 2019

what I've tried to find is a way or an option to just print the whole file content non-interactively with styles and decorations such as line numbers, filename, and colors, which is not achieved by --plain option.

Take a look at the --decorations and --color options. If you set both to "always", you should be able to get what you want.

@jjangga0214
Copy link
Author

jjangga0214 commented Apr 13, 2019

Thanks you @sharkdp!
The below does it.

bat --decorations always --color always <file> | cat

P.S. But if there's an option for it, wouldn't it be convenient? For example, typing that long command might happen more frequent than expected in certain condition. It could be little cumbersome if not using an alias.

@vn971
Copy link

vn971 commented Jul 24, 2023

@jjangga0214 @sharkdp if I understand it correctly, the better command would be:

bat --paging=never <file>

This still includes coloring and decoration by default -- it just doesn't use the pager anymore.

@vn971
Copy link

vn971 commented Jul 24, 2023

Maybe some documentation is worth adding though. E.g. something with the word "interactive mode". I was staring at man bat for quite a long while before I've finally figured out that the key to disable the interactive mode is --paging=never. (As you see I've even had to go online first and find this issue, before finally finding a solution within the manual page after all.)

@vn971
Copy link

vn971 commented Jul 24, 2023

I've also raised an issue now for supporting the non-interactive mode on a global level a bit better: #2629

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants