#!/bin/sh # # Offer a list of background images. # - Cameron Simpson 10may1999 # cmd=$0 usage="Usage: $cmd [-t] [-w] [-r] [-n count] [ptns... [-- directories...]] -n count Choose the first count items. -o \"or\" mode - any pattern may match, not all. -r Randomise output. -t Choose tall images (eg for tty or menu backgrounds). -w Choose wide images (eg for wallpaper)." lfopts= tall= wide= gotptns= badopts= while : do case $1 in -n) lfopts="$lfopts -n $2"; shift ;; -[or]) lfopts="$lfopts $1" ;; -t) wide= tall=1 ;; -w) tall= wide=1 ;; --) gotptns=1; shift; break ;; -?*) echo "$cmd: unrecognised option: $1" >&2 badopts=1 ;; *) break ;; esac shift done [ $badopts ] && { echo "$usage" >&2; exit 2; } ptns= if [ -z "$gotptns" ] then while [ $# -gt 0 ] do case "$1" in --) gotptns=1; shift; break ;; *) ptns="$ptns $1"; shift ;; esac done fi # no dirs? [ $# = 0 ] && { set x `bgdirs`; shift; } filter="awk '{ print \$3 }'" if [ $tall ] then filter="awk '\$1 <= \$2 { print \$3 }'" else if [ $wide ] then filter="awk '\$1 >= \$2 { print \$3 }'" fi fi exec listfiles -f "$filter" $lfopts $ptns -- ${1+"$@"}