Skip to content

Instantly share code, notes, and snippets.

@KSR-Yasuda
Forked from beatlegeuse/man.sh
Last active June 24, 2024 07:58
Show Gist options
  • Save KSR-Yasuda/84349d909bb576b9dfde0bc4914e67b3 to your computer and use it in GitHub Desktop.
Save KSR-Yasuda/84349d909bb576b9dfde0bc4914e67b3 to your computer and use it in GitHub Desktop.
`man` replacement for git bash on windows
#!/bin/bash
# man.sh - `man` replacement for git bash on windows
BASEDIR=$(realpath "${0%/*}")
TEMPDIR=${TMP}
if [[ -z ${TEMPDIR} ]]; then
TEMPDIR=${BASEDIR}
fi
if [[ $# -eq 0 ]]; then
echo "No command specified to get man page for"
exit 1
fi
url="http://man.he.net/?section=all&topic="
# The extra `+` at the end of the querystring doesn't hurt
for arg in $@ ; do
url=$url$arg"+"
done
temp=$(mktemp "${TEMPDIR}/man.XXXXXXXX.tmp") &&
curl -s $url | sed -n '/<PRE>/,/<\/PRE>/p' | sed 's/<[^>]*>//g' | perl -MHTML::Entities -pe 'decode_entities($_);' > "${temp}"
if [[ ! -f ${temp} || $(wc -c < "${temp}") -eq 0 ]]; then
ret=1
echo >&2 "No manual entry for $@"
else
ret=0
less < "${temp}"
fi
if [[ -f ${temp} ]]; then
rm "${temp}"
fi
exit "${ret}"
@KSR-Yasuda
Copy link
Author

Add search result check to return error code if no output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment