1#!/bin/sh
2
3#
4# Copyright (c) 1999 Ethan Fischer
5#
6
7# some useful variables
8nl="
9"
10q='"'
11sednl="\\
12"
13name=`echo "$0" | sed "s@/@$sednl@g" | tail -1`
14
15# set input field separator
16old_ifs="$IFS"
17IFS=$nl
18
19# set defaults
20option_delay="10"
21option_types='*.gif,*.jpg,*.xpm'
22find_args=""
23find_args2=""
24
25# parse options
26while test -n "$1"; do
27	case "$1" in
28		-d|--delay)
29			shift
30			option_delay="$1"
31			;;
32		-e|--repeat)
33			option_repeat=1
34			;;
35		-f|--file)
36			shift
37			option_file="$1"
38			;;
39		-h|--help)
40			option_help=1
41			;;
42		-n|--new-term)
43			option_new_term=1
44			;;
45		-r|--recurse)
46			option_recurse=1
47			;;
48		-R|--random)
49			option_random=1
50			;;
51		-s|--shade)
52			shift
53			option_shade="$1"
54			;;
55		-t|--term)
56			option_term=1
57			;;
58		-v|--version)
59			option_version=1
60			;;
61		-T|--types)
62			shift
63			option_types="$1"
64			;;
65		--)
66			shift
67			break
68			;;
69		-*)
70			echo "Unknown option: $1"
71			exit 1
72			;;
73		*)
74			break
75			;;
76	esac
77	shift
78done
79
80# display version info
81if test -n "$option_version"; then
82	echo "$name version 1.0"
83	exit 0
84fi
85
86# display help
87if test -n "$option_help"; then
88	echo "Usage:"
89	echo "$name [-d] [-e] [-f file] [-h] [-n term] [-r] [-R] [-s %] [-t]"
90	printf "%*s [-T type1,[type2,[...]]] [-v] dirs\\n" ${#name} ""
91	echo "-d (--delay) n     set delay between frames to n seconds (default 10)"
92	echo "-e (--repeat)      repeatedly display list, re-randomizing if --random"
93	echo "-f (--file) f      read image names from file f"
94	echo "-h (--help)        this help"
95	echo "-n (--new-term)    open new aterm, then same as --term"
96	echo "-r (--recurse)     recursive search"
97	echo "-R (--random)      randomize image list"
98	echo "-s (--shade) %     shading option to be passed to aterm (only valid with -n)"
99	echo "-t (--term)        display image in xterm background"
100	echo "-T (--types) types types of files to display; types is a comma-separated"
101	echo '                   list (default is "*.gif,*.jpg,*.xpm")'
102	echo "-v (--version)     display version information"
103	echo "dirs               directories (or files) to search"
104	exit 0
105fi
106
107# need at least one dir
108if test -z "$*" && test -z "$option_file"; then
109	echo "$name: at least one file or directory is required"
110	exit 1
111fi
112
113# follow symlinks
114find_args="-follow"
115
116# set recursion
117if test -z $option_recurse; then
118	find_args="$find_args${nl}-maxdepth${nl}1"
119fi
120
121# set input file
122if test -n "$option_file"; then
123	opts=`cat $option_file`
124else
125  tmp="-name${nl}"`echo $option_types | sed -e "s/,/ -o -name /g" -e "s/ /$sednl/g"`
126	opts=`find "$@" $find_args $tmp | sort | uniq`
127fi
128
129# randomize the list
130if test -n "$option_random"; then
131	opts=`echo "$opts" | randomize`
132fi
133
134if test -n "$option_new_term"; then
135	echo "$opts" > /tmp/slideshow.txt
136	command="slideshow -t -f /tmp/slideshow.txt"
137	if test -n "$option_delay"; then command="$command -d $option_delay"; fi
138	if test -n "$option_repeat"; then command="$command -e"; fi
139	if test -n "$option_recurse"; then command="$command -r"; fi
140	if test -n "$option_random"; then command="$command -R"; fi
141	if test -n "$option_types"; then command="$command -T $option_types"; fi
142	if test -n "$option_shade"; then
143		aterm -sh "$option_shade" +sb -e sh -c "($command &);exec $SHELL"
144	else
145		aterm +sb -e sh -c "($command &);exec $SHELL"
146	fi
147elif test -n "$option_term"; then
148	cont=1
149	while test "$cont" = "1"; do
150		for i in $opts; do
151			echo -n "]20;$i"
152		  sleep $option_delay
153		done
154		cont=$option_repeat
155	done
156else
157	cont=1
158	while test "$cont" = "1"; do
159		for i in $opts; do
160			ascommand.pl "Background "'""'" $i"
161		  sleep $option_delay
162		done
163		cont=$option_repeat
164	done
165fi
166