#!/bin/ksh #..# @(#) squirrel away and use list one by one #..# systems: #..# sites: tag=${0##*/} tm=/tmp/${tag} tmp=${tm}$$ rm -f ${tm}* usage="usage: $tag [-f ] [-{c|l|h|vi|-}] [-t[]] [-] $tag ... $tag [-] \`${tag} [-]\`" nxt="$HOME/.nxt" while [ $# -gt 0 ]; do case "$1" in -v|-x) set "$1" ;; -vi*) ${1#-} $nxt; exit ;; --vi*) ${1#--} $0; exit ;; -about) echo "$tag was written by David Ledger" echo "dledger@ivdcs.demon.co.uk" exit ;; -h) $tag --h | more exit ;; --h) echo "" echo "$usage" echo "" echo "$tag builds a list of items and returns them one at a" echo "time." echo "" echo "With no arguments, $tag returns the next item on the list" echo "and removes that item from the list." echo "" echo "With an argument of -, $tag returns the th item on" echo "the list, and removes that item." echo "" echo "Any argument beginning with '-' other than those listed" echo "below are ignored. Any other argument is added to the" echo "list." echo "" echo "Flags:" echo "-f = specify alt list file." echo "-c = clear the list and continue." echo "-d = remove duplicates ans exit." echo "-h = show this help and exit." echo "-k = move the 1st (th) entry to the end and exit." echo "-l = show entire list and exit." echo "-L = show entire list line numbered and exit." echo "-s = sort list and exit." echo "-t[] = list top 10 () entries and exit." echo "-vi = 'vi' edit list and exit." echo "-- = add '-. to list and continue." echo "" echo "- = take list from stdin and exit." echo "" echo "-x, -v, --h, --vi each have internal functions." echo "" exit ;; -f) [ $# -gt 1 ] || { print "$usage"; exit; } shift nxt="$HOME/$1" ;; -) while read line; do echo "$line" | tr " " "\012" $nxt done exit ;; -c) cp /dev/null $nxt ;; -d) nxt -c $(tr " " "\012" $nxt exit ;; -l) tr "\012" " " $nxt [ $# -le 1 ] && exit ;; -[1-9]*) n=$(expr "$1" : '-\([0-9]*\)') [ "$n" -a "$n" -gt 0 ] || { print "$usage"; exit; } ;; *) echo $* | tr " " "\012" $nxt exit ;; esac shift done [ -f "$nxt" ] || { print -u2 "List empty"; exit 1; } set -A line $(cat $nxt) [ ${#line[*]} -le 0 ] && { print -u2 "List empty"; exit; } [ ${n:=0} -gt 0 ] && n=$((n - 1)) echo ${line[${n}]} [ ${#line[*]} -le 1 ] && { cp /dev/null $nxt; exit; } line[$n]="" set -A line ${line[*]} echo ${line[*]} | tr " " "\012" $nxt | |