Article View: news.software.readers
Article #144766Re: command line newsreader?
From: Chris F.A. Johnson
Date: Thu, 11 Mar 2004 08:25
Date: Thu, 11 Mar 2004 08:25
153 lines
4807 bytes
4807 bytes
On Thu, 11 Mar 2004 at 03:06 GMT, Christopher Browne wrote:
>
> Are you at the command line typing in commands like:
>
> $ folder +comp.os.linux.misc
> $ scan
> $ show 82-90
> $ reply 82
> ???
>
> That's the way a "command line" style of news reading would work, and
> is, in fact, the model established by Rand when they first deployed
> MH. The O.P. asked for "command line;" that involves the model of
> controlling things via a _command line_.
Something like this?
(Type "help" for the commands implemented so far.)
#!/bin/bash
# Thu Mar 11 02:13:02 EST 2004
# NAME: cjnews
# DESCRIPTION: [the beginnings of] a command-line news reader
# Copyright 2004, Chris F.A. Johnson
# Released under the terms of the GNU General Public License
## fill in necessary information here
host=$NNTPSERVER
port=119
user=
pass=
## or put it in $HOME/.cnewsrc, which will be sourced
[ -f "$HOME/.cnewsrc" ] && . $HOME/.cnewsrc
help() {
echo "
COMMANDS:
folder [+]GROUP - select GROUP
group [+]GROUP - select GROUP
head NUMBER - retrieve the head of message no. NUMBER
body NUMBER - retrieve message no. NUMBER
stat NUMBER - get statistics for message no. NUMBER
help - show this screen
quit - exit cjnews
"
}
tcpread() {
while IFS= read -r line <&3
do
line=${line%$CR}
case $line in
.) break ;;
*) printf "%s\n" "$line" ;;
esac
done
}
tcpcmd() {
local IFS=${IFS}$'\r'
cmd=$*
echo $cmd >&3
read ok msg <&3
printf "%s\n" "$ok $msg"
[ ${ok:-666} -lt 400 ]
}
quit() {
tcpcmd quit
echo Exit code: $1
exit $(( $1 % 255 ))
}
folder() {
[ -z "$1" ] && { printf "%s\n" "USAGE: $FUNCNAME [+]name.of.group"; return 192; }
tcpcmd group "${1#+}" && prompt=${1#+}
}
group() {
[ -z "$1" ] && { printf "%s\n" "USAGE: $FUNCNAME [+]name.of.group"; return 192; }
tcpcmd group "${1#+}" && prompt=${1#+}
}
stat() {
[ -z "$1" ] && { printf "%s\n" "USAGE: $FUNCNAME NUMBER"; return 192; }
tcpcmd stat "${@}"
}
head() {
[ -z "$1" ] && { printf "%s\n" "USAGE: $FUNCNAME NUMBER"; return 192; }
tcpcmd head "${@}" && echo || return 192
tcpread
}
body() {
[ -z "$1" ] && { printf "%s\n" "USAGE: $FUNCNAME NUMBER"; return 192; }
tcpcmd body "${@}" && echo || return 192
tcpread
}
HISTFILE=$HOME/.cnewshist
[ -f "$HISTFILE" ] || touch $HISTFILE
history -r
CR=$'\r'
NL=$'\n'
exec 3<>/dev/tcp/$host/$port
read ok msg <&3
echo "$ok $line"
case $ok in
200|201) echo "Connected to $host" ;;
*) quit 192 ;;
esac
[ -n "$user" ] && tcpcmd authinfo simple $user $pass || quit $ok
while :
do
read -ep "${prompt:-$host}:: " cmd
## there must be an easier way to use history in a script
history -w
history -s "$cmd"
history -a
history -c
history -r
case $cmd in
q|Q|[Bb][Yy][Ee]|[Qq][Uu][Ii][Tt]) break ;;
[Gg][Rr][Oo][Uu][Pp]* ) ${cmd} ;;
[Ff][Oo][Ll][Dd][Ee][Rr]*) $cmd ;;
[Ss][Tt][Aa][Tt]*) $cmd ;;
[Hh][Ee][Aa][Dd]*) $cmd ;;
[Bb][Oo][Dd][Yy]*) $cmd ;;
*) help ;;
esac
done
tempfile=$HOME/.cnews-histfile-$$
uniq "$HISTFILE" > $tempfile
mv -b $tempfile "$HISTFILE"
quit 0
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Technical Details
Message-ID:
<c2p7p6$1vur9u$1@ID-210011.news.uni-berlin.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.os.linux.misc.mbox.zip!archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!cpe0030ab04dde2-cm023459906638.cpe.net.cable.rogers.COM!not-for-mailReferences:
<h3F3c.535563$na.1335125@attbi_s04> <%bN3c.32151$aT1.12202@newsread1.news.pas.earthlink.net> <c2od8i$1uk3ac$2@ID-125932.news.uni-berlin.de> <30P3c.1727$YG.17348@attbi_s01> <c2ol36$1u0btk$1@ID-125932.news.uni-berlin.de>Show Full Headers
Complete Article Headers
Message-ID: <c2p7p6$1vur9u$1@ID-210011.news.uni-berlin.de> Subject: Re: command line newsreader? Date: Thu, 11 Mar 2004 08:25:10 +0000 From: "Chris F.A. Johnson" <c.fa.johnson@rogers.com> References: <h3F3c.535563$na.1335125@attbi_s04> <%bN3c.32151$aT1.12202@newsread1.news.pas.earthlink.net> <c2od8i$1uk3ac$2@ID-125932.news.uni-berlin.de> <30P3c.1727$YG.17348@attbi_s01> <c2ol36$1u0btk$1@ID-125932.news.uni-berlin.de> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.os.linux.misc.mbox.zip!archiver1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!cpe0030ab04dde2-cm023459906638.cpe.net.cable.rogers.COM!not-for-mail Newsgroups: comp.os.linux.misc,news.software.readers Lines: 152 NNTP-Posting-Host: cpe0030ab04dde2-cm023459906638.cpe.net.cable.rogers.com (24.156.50.72) X-Trace: news.uni-berlin.de 1078993510 67071294 I 24.156.50.72 ([210011]) User-Agent: slrn/0.9.7.4 (Linux)