Skip to content

Instantly share code, notes, and snippets.

@ksuderman
Last active February 1, 2023 12:37
Show Gist options
  • Save ksuderman/c92cd5e86c70c2018099913587f29c0a to your computer and use it in GitHub Desktop.
Save ksuderman/c92cd5e86c70c2018099913587f29c0a to your computer and use it in GitHub Desktop.
Print simple help with ANSI highlighting
# ANSI color codes for the console.
reset="\033[0m"
bold="\033[1m"
ital="\033[3m" # does not work on OS X
# Function used to highlight text.
function hi() {
echo -e "$bold$@$reset"
}
function help() {
cat | less -RX << EOF
$(hi USAGE)
$(basename $(realpath $0)) [COMMAND] [OPTIONS]
$(hi SYNOPSIS)
Provide a short description here
$(hi COMMANDS)
$(hi command1) Do something
$(hi command2) Do something else
$(hi OPTIONS)
$(hi -o|--option) flag me
$(hi EXAMPLES)
EOF
}
if [[ $# == 0 ]] ; then
help
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment