#! /bin/bash

## 
## Usage: @PROG@ FILENAME
## 
##   Uses gxmessage to view the specified file, with an
##   option to edit it.
## 


PROG=$(basename $0)
XMESSAGE=gxmessage
GEOMETRY="800x600"
# GEOMETRY="1024x768"
FONT="mono 11"
GEDIT=gedit


invocationError ()
{
  echo "Try '$PROG -h'" >&2
  exit 64
}


showUsage ()
{
  sed -n '/^##/s/^## //p' $0 |
  sed -e "s/@PROG@/${PROG}/g"
  exit 0
}


[ "$1" = "-h" -o "$1" = "--help" ] && showUsage
[ "$#" -ne 1 ] && invocationError


filename="$1"


$XMESSAGE -title "gxview"       \
          -geometry "$GEOMETRY" \
          -font "$FONT"         \
          -buttons "Edit,Close" \
          -default Close        \
          -file "$filename"

[ "$?" -eq 101 ] && $GEDIT "$filename"


exit 0

