Skip to content

Instantly share code, notes, and snippets.

@minhtrancccp
Created June 22, 2024 02:56
Show Gist options
  • Save minhtrancccp/f1ec56d17c5be28aaee8cc97079152a5 to your computer and use it in GitHub Desktop.
Save minhtrancccp/f1ec56d17c5be28aaee8cc97079152a5 to your computer and use it in GitHub Desktop.
an extension to the help builtin of bash, with stdout colorisation and paging of bat
#!/bin/bash
# based on https://github.com/sharkdp/bat#highlighting---help-messages
help() {
{
set -x
command help "$@" 2>/dev/null
type -P "$1" && if echo "$@" | grep -Eq '(\s-h|help)(\s|$)'; then "$@"; else "$@" --help; fi
} |& bat -plhelp
}
complete -F _command help # https://stackoverflow.com/a/35356591/8867832
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment