Permalink
Browse files

bman(1) contrib script opens man page in browser w/ basic formatting

  • Loading branch information...
1 parent bfa6a79 commit ae9c3ac82a4637bc99660d22d959640aa1cff740 @nickstenning nickstenning committed with Aug 22, 2010
Showing with 26 additions and 0 deletions.
  1. +26 −0 contrib/bman
View
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Usage: bman <man-args>
+# Open manual page in browser with bcat.
+#
+# Original zsh version by Nick Stenning <http://github.com/nickstenning>
+# http://github.com/rtomayko/bcat/issues#issue/8
+#
+# Ported to POSIX shell by Ryan Tomayko <http://github.com/rtomayko>
+set -e
+
+# we use normal bold and underline
+BOLD="\033[1m"
+EM="\033[3m"
+RESET="\033[0m"
+
+# pass argv directly over to man
+man "$@" |
+
+# replace ^H based bold and underline with ansi equivelants
+sed "
+ s/_\(.\)/"$(echo "$EM")"\1"$(echo "$RESET")"/g
+ s/\(.\)\1/"$(echo "$BOLD")"\1"$(echo "$RESET")"/g
+" |
+
+# pipe it into bcat
+bcat

1 comment on commit ae9c3ac

Owner

rtomayko commented on ae9c3ac Aug 22, 2010

Nick's original zsh version is:

function bman {
  colors
  local bold=$'\\(.\\)\b\\1'
  local ul=$'_\b\\(.\\)'
  man ${@} | sed "s/${bold}/$fg_bold[blue]\1$reset_color/g;s/${ul}/$fg_bold[red]\1$reset_color/g" | bcat
}

I wanted to credit him in --author but he shouldn't be held responsible for my crappy POSIX shell shown here :)

Please sign in to comment.