I call cat when I need to pipe or copy something, and just bat if I wanna read it myself. I find this as a good compromise, I like how bat formats things.
Your solution would be ok with an alias as well, so thanks. Might try it just so I dont need yet another program lying around
That has git integration, like bat does? That shows non-printable characters like bat does? That allows you to concatenate and page multiple files at once like bat does? That supports the --line-range option like bat does? You can pipe the output of tail -f through your alias?
I guess if all you did was read the headline of the post you could assume your alias does all the same things as bat.
oh, i feel stupid now, the reason bat worked and highlight didn't was because bat had access to the filename extension. if highlight is called with a filename argument it can detect the syntax too.
so really bat and hightlight are equal, and it's not just a useless use of cat, but using cat here actually breaks the syntax detection. and it does so in bat too, obviously.
so this means highlight almost wins because it has pike support already, whereas for bat i had to add it, except that it turns out that if highlight can't detect the syntax it produces nothing, and you need --force to fix that, and if it is given multiple files as arguments it writes the output to files too, which is practically never what i want so i need to fix that with --stdout.
Although I agree with other commenters that your command can't compare to all of bat's features, many of which I appreciate... thank you for sharing this tip, I didn't know about `highlight` and I can't install `bat` at work.
This will live in my .bashrc for a long time:
cat() {
if [[ -t 1 ]]; then
command cat "$@" | highlight --force -O xterm256
else
# plain cat to pipe into other things
command cat "$@"
fi
}
Very cool tool. It's perfect for the "take a quick look" use-case.
I just downloaded it on MacOS and when I ran it the first time it took a really long time on a one-line JSON which disappointed me but then any subsequent run on anything was fast. I'd completely forgotten about MacOS doing that thing on first run.
Uses the pager for large files automatically etc. Very nice.
> Uses the pager for large files automatically etc. Very nice.
If you like that, you can also make less behave like cat if the file fits in one screen. You just need to add F to the LESS environment variable. It's very convenient because so many things depend on less.
20 comments
[ 2.5 ms ] story [ 39.0 ms ] threadworks fine for me.
Your solution would be ok with an alias as well, so thanks. Might try it just so I dont need yet another program lying around
I guess if all you did was read the headline of the post you could assume your alias does all the same things as bat.
so apparently, no, it doesn't work.
to be fair, this is how it works:
to avoid getting caught by the useless use of cat police, this does too: however, i have to tell it which syntax to usebut to its credit, highlight even has support for pike, which bat doesn't (yet) (fixed that for myself, at least)
so overall, bat wins.
so really bat and hightlight are equal, and it's not just a useless use of cat, but using cat here actually breaks the syntax detection. and it does so in bat too, obviously.
so this means highlight almost wins because it has pike support already, whereas for bat i had to add it, except that it turns out that if highlight can't detect the syntax it produces nothing, and you need --force to fix that, and if it is given multiple files as arguments it writes the output to files too, which is practically never what i want so i need to fix that with --stdout.
bat it is.
This will live in my .bashrc for a long time:
i'd change the third line so you can actually get syntax highlighting:
https://news.ycombinator.com/from?site=github.com/sharkdp
Like rg, it's one of those "rewrite it in rust" projects that turned out to actually be quite well thought through.
[0] https://www.gnu.org/software/src-highlite/
I just downloaded it on MacOS and when I ran it the first time it took a really long time on a one-line JSON which disappointed me but then any subsequent run on anything was fast. I'd completely forgotten about MacOS doing that thing on first run.
Uses the pager for large files automatically etc. Very nice.
If you like that, you can also make less behave like cat if the file fits in one screen. You just need to add F to the LESS environment variable. It's very convenient because so many things depend on less.
https://www.man7.org/linux/man-pages/man1/less.1.html#:~:tex...
bat: A cat(1) Clone with Wings - https://news.ycombinator.com/item?id=33382307 - Oct 2022 (2 comments)
bat, a cat(1) clone with syntax highlighting, Git integration written in Rust - https://news.ycombinator.com/item?id=24850244 - Oct 2020 (6 comments)
Bat: A cat(1) clone with wings - https://news.ycombinator.com/item?id=17887819 - Aug 2018 (12 comments)
Bat: A cat(1) clone with wings - https://news.ycombinator.com/item?id=17849535 - Aug 2018 (1 comment)
Bat: cat(1) clone with syntax highlighting and Git integration - https://news.ycombinator.com/item?id=16968755 - May 2018 (1 comment)