Skip to content

Instantly share code, notes, and snippets.

@int3h
Created May 2, 2013 12:36
Show Gist options
  • Save int3h/5501914 to your computer and use it in GitHub Desktop.
Save int3h/5501914 to your computer and use it in GitHub Desktop.
hman: a bash function for Mac OS X which lets you view a man page as a nicely formatted HTML page in your browser. Source this file in your ~/.bash_profile (e.g., add a line like "source ~/hman.sh" to that file) and re-open your Terminal. Use as in "hman bash". Tested on Mac OS X 10.8.3. Requires a newer version of "groff" than comes with the OS…
#!/usr/bin/env bash
hman () {
local TMPHTML=`mktemp /tmp/hman_XXXXXXXX`.html
groff -mandoc -Txhtml -P'-D/tmp' `man -w $@` | \
tidy -ashtml 2>/dev/null | \
sed -e 's/<\/style>/body {font-family: "Helvetica Neue", Helvetica, sans-serif; width: 800px; margin-left: auto; margin-right: auto;}\
.toc {position: fixed; overflow-y: scroll; overflow-x: hidden; top: 10px; height: 90%; width: 200px; text-transform: lowercase; margin-left: -200px; margin-top: 1.5em; font-size: 11pt; border-right: 1px solid black; }\
.toc a { line-height: 2em; }\
.toc p { margin-top: 0em; }\
.content { font-size: 10pt; margin-left: 50px; }\
h1 { font-weight: 300; font-size: 64px; margin-top: 0em; letter-spacing: -2px; }\
h2 { margin-top: 2.5em; font-weight: 300;} \
p { line-height: 1.25em; margin-top: 1.2em; }\
h2 + p { margin-top: 0em !important; }<\/style>/' \
-e 's/<p><a href="#heading1">/<div class="toc">\
<p><a href="#heading1">/' \
-e 's/<hr>/<\/div>/' \
-e 's/<h2 id="heading1">/<div class="content">\
<h2 id="heading1">/' > "$TMPHTML"
open "$TMPHTML"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment