Open KaBankz opened 6 months ago
Thanks for reporting this @KaBankz! Unfortunately, this kind of help message is intractable for cmd-help
.
It seems like fish
's help message uses overstrike formatting [1]. Notice in the copypasted help message how some lines have lots of
char X + mystery char ? + char X again
I'm guessing the unknown char is a backspace, which checks out with how this combination is represented as a bold char X (see the screenshots).
It'd be super complicated to handle this with a sublime syntax, so I decided early on [2] that cmd-help
wouldn't cover this use case...
I appreciate your reporting this in any case! Also, if cmd-help
was useful to you please give it a star!
Unfortunate for fish, but thanks anyway for this cool tool, it's made my help usage much more pleasant.
Hi @KaBankz !
I've given this another look and maybe we can strip special characters from the input before it reaches the syntax.
Can you try running this?
fish --help | sed -r "s,\x1B\[[0-9;]*[mK],,g" | bat -plhelp
You could later put that sed
command into an alias, perhaps, or the entire | sed ... | bat ...
line.
If it works, I'll probably add it to the suggested configuration in the docs.
That particular sed command comes from this StackOverflow answer.
If you're on a BSD system (e.g.: MacOS), you may need to try this one.
Hey @victor-gp,
The sed
commands you provided didn't work, I'm on MacOS btw, and none of the sed
commands from the linked StackOverflow worked for me.
I did some digging myself and no luck, but then I decided to ask ChatGPT, and low and behold, it gave me:
sed 's/.\x08//g'
.\x08
: represents the backspace character, this is typical of overstriking where one character overlays another. â ChatGPT
This seems to work perfectly to convert the overstriking formatted output to plaintext
Before:
fish - the friendly interactive shell
ffiisshh [_O_P_T_I_O_N_S] [_F_I_L_E [_A_R_G ...]]
ffiisshh [_O_P_T_I_O_N_S] [--cc _C_O_M_M_A_N_D [_A_R_G ...]]
After:
fish - the friendly interactive shell
fish [OPTIONS] [FILE [ARG ...]]
fish [OPTIONS] [-c COMMAND [ARG ...]]
Now using it with bat -lhelp
works as expected
fish --help | sed 's/.\x08//g' | bat -lhelp
Although some nested stuff is not highlighted and some flags are highlighted while others are not, not sure if this is expected behavior or a bug: (sorry for the obnoxious arrows)
Other than that, this solution seems to work perfect for fish!
fish
đfish --help | sed 's/.\x08//g' | bat -lhelp
description
The fish shell's help command output is not highlighted at all.
When piping into bat:
Regular:
$ bat --version
bat 0.24.0
$ fish --help
$ fish --version
3.7.1