#!/bin/sh # # List and read news articles # export PAGER="less -F" trap 'rm -f $tmpfile; exit' 0 1 2 3 13 15 # If any command line argument is given, list and read all articles, # otherwise only unread ones [ $# -ne 0 ] && { iflag=-i; nflag="-n all"; } invalid() { echo "Invalid response"; sleep 1 } tmpfile=$(mktemp ~/.lrn.XXXXXX) || exit 1 while :; do if [ -z "$group" ]; then readnews -C $iflag $nflag | nawk ' /^[[:space:]]/ { printf "%4d %s\n", ++n, $1 }' >$tmpfile [ -s $tmpfile ] || exit n=0 while read line; do eval "group$n=\${line##* }" n=$(($n + 1)) done <$tmpfile ${PAGER} $tmpfile printf "\nGroup: " read r || exit [ -z "$r" ] && continue case "$r" in [!0-9]*) invalid; continue;; esac [ $r -lt 1 -o $r -gt $n ] && { invalid; continue; } eval "group=\$group$(($r - 1))" fi readnews -n $group -l $iflag | sed -n '/^ /p' >$tmpfile [ -s $tmpfile ] || { group=; continue; } ${PAGER} $tmpfile printf "\nPress to read articles, EOF to return to the groups..." read r || { group=; continue; } readnews -n $group $iflag done .