File: gxview

package info (click to toggle)
gmessage 2.4.2-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 500 kB
  • ctags: 118
  • sloc: sh: 3,168; ansic: 805; makefile: 72
file content (88 lines) | stat: -rwxr-xr-x 1,572 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! /bin/bash

## 
## Usage: @PROG@ [OPTIONS] [FILE]
## 
##   Uses gxmessage to view a file, with options to edit or print
## 
## Options:
##   -c          center
##   -f COLOUR   foreground colour
##   -b COLOUR   background colour
##   -h          help
## 


PROG=$(basename $0)
XMESSAGE=${XMESSAGE:-$(which gxmessage)} || XMESSAGE=xmessage
GEDIT=gedit

MSG_TITLE=$PROG
MSG_FG=black
MSG_BG=white
MSG_GEOM="800x600"
MSG_FONT="mono 11"


[ "$XMESSAGE" = xmessage ] && MSG_FONT=


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


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


while getopts ":chf:b:" Option
do
  case $Option in
  c) center=1 ;;
  f) msg_fg=$OPTARG ;;
  b) msg_bg=$OPTARG ;;
  h) showUsage ;;
  *) invocationError ;;
  esac
done
shift $(($OPTIND - 1))
[ "$#" -gt 1 ] && invocationError


filename="${1:--}"

if [ "$filename" = "-" ]; then
  buttons="GTK_STOCK_CLOSE:103"
else
  MSG_TITLE="$MSG_TITLE: $filename"
  buttons="GTK_STOCK_OPEN:101,GTK_STOCK_PRINT:102,GTK_STOCK_CLOSE:103"
fi


$XMESSAGE -title "$MSG_TITLE"            \
          -geometry "$MSG_GEOM"          \
          ${center:+-center}             \
          ${MSG_FONT:+-font "$MSG_FONT"} \
          -fg "${msg_fg:-$MSG_FG}"       \
          -bg "${msg_bg:-$MSG_BG}"       \
          -buttons "$buttons"            \
          -default GTK_STOCK_CLOSE       \
          -file "$filename"

action=$?
if [ "$action" -eq 101 ]; then
  $GEDIT "$filename"
elif [ "$action" -eq 102 ]; then
  enscript -G "$filename" | lpr
fi


exit 0