Repository navigation
Replies: 1 comment
|
Hi! I got curious and tried it out myself. You're right, shfmt doesn't do any coloring. It only changes the layout of the code, and I checked that its output has no color codes at all. So highlighting is bat's job, and piping shfmt into bat like you do is the right approach. Your (1) and (2) aren't actually identical, though. The differences are just really easy to miss. I tried a small function like this: _example() { if [ -n "$1" ]; then echo "hi $1"; else for f in a b; do echo $f; done; fi; }
diff <(declare -f _example) <(declare -f _example | shfmt -ln bash)and got: < _example ()
< {
< if [ -n "$1" ]; then
< echo "hi $1";
< else
< for f in a b;
< do
< echo $f;
< done;
< fi
---
> _example() {
> if [ -n "$1" ]; then
> echo "hi $1"
> else
> for f in a b; do
> echo $f
> done
> fi
(I tested on bash 3.2, so your |
Uh oh!
There was an error while loading. Please reload this page.
shfmthas no syntax formatting as far as I can see?I should let
batformat and syntax highlight.Can
shfmtsyntax format?(2) looks identical to (1) to me.
(1)
declare -f _example | shfmt -ln bash | bat -l bash --paging=never --style=full --decorations=always --color=always(2)
declare -f _example | bat -l bash --paging=never --style=full --decorations=always --color=alwaysAll reactions