-
Notifications
You must be signed in to change notification settings - Fork 5
Configuration tips
The following configuration tips work for Bash, Zsh and Fish unless otherwise stated.
These config lines should go in your respective shell's configuration file (.bashrc, .zshrc, .config.fish, etc.)
There's a snippets section at the end including all of the options discussed here.
Contributions are very welcome for covering other shell environments, including Windows shells like Powershell.
Add an alias with all the options you want when running a help message through bat + cmd-help.
For instance, the bare minimum is this:
alias bathelp="bat --plain --language=help"Then you can use it like $ <CMD> --help | bathelp
You may want to add further options to the bat command:
-
--theme='<THEME_NAME>', if you want to use a differentbattheme than your default. -
--paging=alwaysif you wantbatto always use a pager when displaying the help message, even when it fits the screen. -
--paging=neverif you never want, even when the help message doesn't fit the screen. - etc.
You can add a help function so you can do $ help <CMD>
For Bash, Zsh:
help() {
"$@" --help 2>&1 | bathelp
}For Fish:
function help
$argv --help 2>&1 | bathelp
endCaveats, considerations:
-
Bash has a
helpbuiltin, this function would override it.- You could name the function differently, e.g.:
helpb,bhelp. - Or if you override it, you can still use the original with the
commandbuiltin:$ command help <ARGS>
- You could name the function differently, e.g.:
- This function works for subcommands too, you can do
$ help <CMD> <SUBCMD>. Try$ help git commit - Depending on the command, it may also handle alternative help options, e.g.,
$ help bat -h- When it doesn't work, you can always fall back to
bathelp.
- When it doesn't work, you can always fall back to
You can make --help into a global alias (Zsh) or an abbreviation (Fish) to enhance the default form: $ <CMD> --help
You can also do the same for the shorthand -h.
For Zsh:
alias -g -- --help='--help 2>&1 | bathelp'
alias -g -- -h='-h 2>&1 | bathelp'For Fish:
abbr --add --position=anywhere -- --help '--help 2>&1 | bathelp'
abbr --add --position=anywhere -- -h '-h 2>&1 | bathelp'Caveats, considerations:
- In some cases,
-his not a shorthand for--help(e.g.:ls). - To run the default, unaltered
--help:- On Zsh: prepend it with a backslash:
$ <CMD> \--help - On Fish: press
Ctrl+Spaceafter--helpand it won't expand the abbreviation.
- On Zsh: prepend it with a backslash:
- Alternatively, you can name the alias something like
--helpb.- Which is friendly to edit into a previous
--helpcommand withArrowUp.
- Which is friendly to edit into a previous
- Enhancing
--helpalso has the benefit that you can add runtime options tobathelp(unlike when using ahelpfunction).- e.g.: if you want a help message not to be paginated, you can do:
$ <CMD> --help --paging=never
- e.g.: if you want a help message not to be paginated, you can do:
Some commands format their help messages with characters that are intractable to cmd-help. In such cases, the syntax exits early.
However, you can ensure the syntax functions as expected by removing those special characters before cmd-help parses the help message.
Some commands use overstriking for their help messages (e.g.: less, fish).
You can remove overstriking by adding this sed filter before the bat command:
alias bathelp="sed 's/.\x08//g' | bat --plain --language=help"cmd-help can't handle escape sequences like color codes, bold or underline.
Most commands don't include this kind of formatting in their help message when they run into a pipe, like when using bathelp. But some still print them (e.g.: the delta git pager).
You can remove escape sequences by adding --strip-ansi to your bathelp options:
alias bathelp="bat --plain --language=help --strip-ansi=always"Caveats, considerations:
- If the help message is already formatted (especially with ANSI color codes), chances are that
cmd-helpwon't do a better job at highlighting the message's syntax. - On the other hand, you may still prefer the familiarity and consistency of the
bathelpsyntax highlighing.
These snippets include all of the options discussed in this page. Use the snippet that applies to your shell.
We recommend that you make this config yours by removing things you don't want/need, customizing the bat theme, perhaps adding other bat options, etc.
alias bathelp="sed 's/.\x08//g' | bat --plain --language=help --strip-ansi=always"
help() {
"$@" --help 2>&1 | bathelp
}alias bathelp="sed 's/.\x08//g' | bat --plain --language=help --strip-ansi=always"
help() {
"$@" --help 2>&1 | bathelp
}
alias -g -- --help='--help 2>&1 | bathelp'
alias -g -- -h='-h 2>&1 | bathelp'alias bathelp="sed 's/.\x08//g' | bat --plain --language=help --strip-ansi=always"
function help
$argv --help 2>&1 | bathelp
end
abbr --add --position=anywhere -- --help '--help 2>&1 | bathelp'
abbr --add --position=anywhere -- -h '-h 2>&1 | bathelp'contributions to this wiki are welcome! :D
if cmd-help is useful to you, please give it a star ⭐