#!/bin/ksh #..# @(#) squirrel away and use list one by one #..# systems: #..# sites: #..# level: #..# publish: y #..# keys: #..# date: Fri Jan 12 15:48:02 GMT 2001 #..# vers: 9 [ $0 = ${0#/} ] && this=$(pwd -H)/$0 || this=$0 tag=${0##*/} tm=/tmp/${tag} tmp=${tm}$$ rm -f ${tm}* set -A AWK $(whence nawk) [ ${#AWK[*]} -gt 0 -a "${AWK[0]}" != no ] && alias awk=${AWK[0]} usage="usage: $tag [-f ] [-{c|l|h|e|-}] [-t[]] [-] $tag ... $tag [-] \`${tag} [-]\`" # set -- `getopt vxh $*` nxt="$HOME/.nxt" while [ $# -gt 0 ]; do case "$1" in -v|-x) set "$1" ;; -vi) lockvi $this; exit ;; -view) view $0; exit ;; -about) echo "$tag was written by David Ledger" echo "dledger@ivdcs.co.uk" echo "Free to use at your own risk" echo "Copyright 2004" exit ;; -ver) ver=$(egrep '#..#[ ]*vers:' $this) ver=${ver#"${ver%%[1-9]*}"} print ${ver%%[!0-9]*} 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 and 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 "-S = show list in easy read format" echo "-t[] = list top 10 () entries and exit." echo "-e = '${VISUAL}' edit list and exit." echo "-- = add '-. to list and continue." echo "" echo "As a special case, -l -c and -S -c show list, then clear" echo "it." echo "" echo "- = take list from stdin and exit." echo "" echo "-h, -v, -x, -var, -about, -vi, -view have the standard" echo "functionality for my commands" echo "" echo "--h, --vi each have internal functions." echo "" exit ;; -f) [ $# -gt 1 ] || { print "$usage"; exit; } shift nxt="$1" ;; -) while read line; do echo "$line" | tr " " "\012" >> $nxt done exit ;; -c) cp /dev/null $nxt ;; -d) nxt -c $(tr " " "\012" < $nxt | cat -b - | sort -u +1 | sort +0n -1 | cut -f 2) exit ;; -e) ${VISUAL-vi} $nxt; exit ;; -k) set -A line $(cat $nxt) [ ${n:=0} -gt 0 ] && n=$((n - 1)) t=${line[$n]} line[$n]="" echo ${line[*]} $t | tr " " "\012" > $nxt exit ;; -l) cat $nxt [ $# -gt 1 ] && [ "$2" = "-c" ] && > $nxt exit ;; -L) cat -b $nxt exit ;; -s) nxt -c $(tr " " "\012" < $nxt | sort) exit ;; -S) tr "\012" " " < $nxt | fold -s [ $# -gt 1 ] && [ "$2" = "-c" ] && > $nxt exit ;; -t*) n=${1#-t} head -${n:-10} $nxt | tr "\012" " " | fold -s exit ;; --) echo ${1#-} >> $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; } 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