#!/bin/sh

###############################################################################
#									      #
#	      GNU Interactive Tools 4.3.9 per file type action script	      #
#				   Global version			      #
#	         Copyright (C) 1994 Free Software Foundation, Inc.	      #
#		    Written by Tudor Hulubei and Andrei Pitis.		      #
#			  Enhanced by Verdoolaege Sven.		              #
#									      #
###############################################################################

#
# This script executes a different action for each file type specified.
# It tries to match the second parameter against the patterns
# specified in the 'case' statement (see below).
#
# If you want to add new file types & actions to this script, just add a
# new entry to the 'case' statement *before* the last one ( *) ... )
#
# For grater flexibility, gitaction's first parameter is the name of the
# directory where the file resides. So, you can get the complete file
# name appending the file base name to the file path just like that: $1/$2
#
# If you enhance this script, please send me a patch (tudor@chang.pub.ro).
# I'll include it in the next release.
#

#
# The original patch sent by Verdoolaege Sven had 'less' instead of more.
# I don't know if all Unix systems have 'less', but I am pretty sure they
# have 'more', so I've put 'more' back, for the sake of portability.
# If I am wrong, please email me.  Anyway, if you really want 'less', feel
# free to change :-)
#
# NEWS !!!
#   Instead of hardcoding "more" or "less" here, we can now use GIT_PAGER, a
# shell environment variable that binds on one of them, depending on your
# environment.  The default is to call "more", but if you change your
# GIT_PAGER environment variable, you will hopefully use "less" or any pager
# you like.
#

#
# Thanks to John Stump for suggesting me to get rid of gitmatch.
#

name=`basename "$0"`

if test "$#" -ne 2 -o ! -d "$1" -o ! -f "$2"; then
	echo "$name: GIT internal script" >&2
	exit 1
fi

done=0

if test -f .gitaction; then
	./.gitaction "$1" "$2"
	done=$?
fi

if test $done -ne 0; then
	exit 0
fi


msg="Press ENTER to continue"


case "$2" in

*.[oO])	 	objdump --syms --all-headers "$2" | $GIT_PAGER;		\
		echo $msg; read key;;
*.a | *.sa)	ar -tv "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*.tar)		tar tvf "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*.tar.gz |\
*.t[arg]z |\
*.tar.[zZ])	(echo "Compressed file info:";				\
		gunzip -l "$2";						\
		echo;							\
		echo "Tar file info:";					\
		gunzip -c "$2" | tar tvf - ) | $GIT_PAGER;		\
		echo $msg; read key;;
*.man)		nroff -man "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*.html |\
*.htm)		lynx "$2";;
utmp)		w | $GIT_PAGER;						\
		echo $msg; read key;;
wtmp)		last | $GIT_PAGER;					\
		echo $msg; read key;;
pubring.pgp |\
secring.pgp)	pgp -kv "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*.fig | *.FIG)	if test $DISPLAY; then					\
			(xfig "$2" > /dev/null 2>&1 &);			\
		else							\
			$GIT_PAGER "$2";				\
			echo $msg; read key;				\
		fi;;
*.gif  | *.GIF  |\
*.jpg  | *.JPG  |\
*.jpeg | *.JPEG |\
*.tga  | *.TGA  |\
*.bmp  | *.BMP  |\
*.ppm  | *.PPM  |\
*.pgm  | *.PGM  |\
*.pbm  | *.PBM)	if test $DISPLAY; then					\
			(xv "$2" > /dev/null 2>&1 &);			\
		else							\
			zgv "$2";					\
		fi;;
*.tif | *.TIF |\
*.xbm | *.XBM |\
*.xpm | *.XPM |\
*.ras | *.RAS |\
*.rgb | *.RGB |\
*.fts | *.FTS |\
*.pm  | *.PM)   if test $DISPLAY; then					\
			(xv "$2" > /dev/null 2>&1 &);			\
		else							\
			$GIT_PAGER "$2";				\
			echo $msg; read key;				\
		fi;;
*.mpeg | *.MPEG |\
*.mpg  | *.MPG) if test $DISPLAY; then					\
			(mpeg_play "$2" > /dev/null 2>&1 &);		\
		else							\
			mpeg_vga "$2";					\
		fi;;
*.mpg.gz    |\
*.MPG.gz    |\
*.mpg.[zZ]  |\
*.MPG.[zZ]  |\
*.mpeg.gz   |\
*.MPEG.gz   |\
*.mpeg.[zZ] |\
*.MPEG.[zZ])	if test $DISPLAY; then					\
			(gunzip -c "$2" | mpeg_play > /dev/null 2>&1 &);\
		else							\
			gunzip -c "$2" | mpeg_vga;			\
		fi;;
*.fli | *.FLI |\
*.flc | *.FLC)	if test $DISPLAY; then					\
			(xanim "$2" > /dev/null 2>&1 &);		\
		else							\
			flip "$2";					\
		fi;;
*.fli.gz   |\
*.FLI.gz   |\
*.fli.[zZ] |\
*.FLI.[zZ] |\
*.flc.gz   |\
*.FLC.gz   |\
*.flc.[zZ] |\
*.FLC.[zZ])	if test $DISPLAY; then					\
			(gunzip -c "$2" | xanim > /dev/null 2>&1 &);	\
		else							\
			gunzip -c "$2" | flip -;
		fi;;
*.gl | *.GL)	if test $DISPLAY; then					\
			(xgrasp "$2" > /dev/null 2>&1 &);		\
		else							\
			$GIT_PAGER "$2";				\
			echo $msg; read key;				\
		fi;;
*.gl.gz   |\
*.GL.gz   |\
*.gl.[zZ] |\
*.GL.[zZ])	if test $DISPLAY; then					\
			(gunzip -c "$2" | xgrasp > /dev/null 2>&1 &);	\
		else							\
			$GIT_PAGER "$2";				\
			echo $msg; read key;				\
		fi;;
*.mod | *.s3m)	(s3mod "$2" &);;
*.voc | *.wav)	(vplay "$2" &);;
*.ps | *.PS)	if test $DISPLAY; then					\
			(ghostview "$2" > /dev/null 2>&1 &);		\
		else							\
		gs -sDEVICE=linux "$2";					\
		fi;;
*.dvi | *.DVI)	if test $DISPLAY; then					\
			(xdvi "$2" > /dev/null 2>&1 &);			\
		else							\
			$GIT_PAGER "$2";				\
			echo $msg; read key;				\
		fi;;
*.[1-9n] |\
*.[1-9n][xXm])	nroff -man "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*.[1-9n][xXm].gz   |\
*.[1-9n][xXm].[zZ] |\
*.[1-9n].gz        |\
*.[1-9n].[zZ])	gunzip -c "$2" | nroff -man | $GIT_PAGER;		\
		echo $msg; read key;;
RMAIL)		emacs -f rmail;;
*.gz  | *.GZ |\
*.[zZ])		gunzip -c "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*.zip | *.ZIP)	unzip -v "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*.arj | *.ARJ |\
*.a[0-9][1-9] |\
*.A[0-9][1-9])	unarj l "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*.rar | *.RAR)	unrar l "$2" | $GIT_PAGER;				\
		echo $msg; read key;;
*)		$GIT_PAGER "$2";					\
		echo $msg; read key;;

esac

exit 0
