Skip to content

Instantly share code, notes, and snippets.

@gwash
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwash/11ba428e4b6a681b7502 to your computer and use it in GitHub Desktop.
Save gwash/11ba428e4b6a681b7502 to your computer and use it in GitHub Desktop.
Shell CHM file handler using Archmage
#!/bin/sh
#by M Rawash <mrawash@gmail.com>
#requires archmage
[[ $BROWSER ]] || BROWSER='w3m -F'
if test "$1" = "-l"; then
shift
PORT=$((10000+$RANDOM))
archmage -p $PORT "$@" &
sleep 2
$BROWSER "http://localhost:$PORT"
wait
exit 0
elif test "$1" = "-t"; then
shift
TMPDIR="/tmp/archmage_${@}"
archmage "$@" "${TMPDIR}"
$BROWSER "${TMPDIR}/index.html"
exit 0
elif test "$1" = "-e"; then
shift
archmage "$@"
exit 0
elif test "$1" = "-ct"; then
shift
archmage -c text "$@"
exit 0
elif test "$1" = "-ch"; then
#requires htmldoc
#FIXME
shift
archmage -c html "$@"
exit 0
elif test "$1" = "-cp"; then
#requires htmldoc
#FIXME
shift
archmage -c pdf "$@"
exit 0
elif test "$#" -gt 2; then
echo "Invalid argument(s)"
exit 1
else
#requires w3m
archmage -d "$@" | w3m -T text/html
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment