-
-
Save KSR-Yasuda/84349d909bb576b9dfde0bc4914e67b3 to your computer and use it in GitHub Desktop.
`man` replacement for git bash on windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add search result check to return error code if no output.