Skip to content

Instantly share code, notes, and snippets.

@pgmccann
Last active April 25, 2017 11:49
Show Gist options
  • Save pgmccann/86cf2aa493513815f277542343a517aa to your computer and use it in GitHub Desktop.
Save pgmccann/86cf2aa493513815f277542343a517aa to your computer and use it in GitHub Desktop.
Having "man <cmd>" fall back on "<cmd> --help" in zsh with oh-myzsh colored-man-pages
function man() {
CLRD_MAN=$ZSH/plugins/colored-man-pages/colored-man-pages.plugin.zsh
PGR='less'
OTHER_OPTS=0
while getopts ":P:" opt; do
case $opt in
P ) PGR=$OPTARG ;;
? ) OTHER_OPTS=1 ;;
esac
done
if (( OTHER_OPTS == 1 )) then
. $CLRD_MAN && man $@
else
/usr/bin/man -P cat ${@: -1} > /dev/null && (. $CLRD_MAN && man $@) || (${@: -1} --help > /dev/null && ${@: -1} --help | $PGR || echo "No help content found")
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment