shithub: riscv

Download patch

ref: 9c70c81e708bf576833b8f2079c0c07242c1c8cc
parent: ce17224eaf159e48b4cbb40c437bb2b3e008ca9e
author: stanley lieber <stanley.lieber@gmail.com>
date: Fri May 26 07:15:35 EDT 2017

newt: honor environment variables $editor and $pager

--- a/rc/bin/newt
+++ b/rc/bin/newt
@@ -6,6 +6,8 @@
 argv0=$0
 if(~ $#editor 0)
 	editor=hold
+if(~ $#pager 0)
+	pager=cat
 group=alt/test
 maxposts=30
 mnt=/mnt/news
@@ -97,7 +99,8 @@
 	f $mnt/$* |
 		grep -v -e '\/([0-9]+|article|body|header|post|xover)$' |
 		sed 's/^'$"kmnt'\//  g	/g' |
-		sort
+		sort |
+		eval $pager
 }
 fn nshift{ shift; echo $* }
 fn printhelp{
@@ -121,7 +124,7 @@
 ||cmd		pipe raw message to a command
 ?		print debug information'
 }
-fn p{
+fn np{
 	if(test $1 -le $#rposts && test -f $mnt/$group/$rposts($1)^/body){
 		{ # don't stutter
 			grep -e '(^From|^Newsgroups|^Subject|^Date)' $rposts($1)^/header
@@ -128,7 +131,7 @@
 			echo
 			cat $rposts($1)^/body
 		} >/tmp/p
-		cat /tmp/p
+		eval $pager /tmp/p
 	}
 	echo
 	go=1
@@ -138,7 +141,7 @@
 }
 fn P{
 	if(test $1 -le $#rposts && test -f $mnt/$group/$rposts($1)^/article)
-		cat $rposts($1)^/article
+		eval $pager $rposts($1)^/article
 	echo
 	go=1
 	r=$1
@@ -262,10 +265,11 @@
 		k `{nshift $cmd | sed 's/\./\//g'}
 	case kf' '*
 		grep -e `{nshift $cmd} $home/lib/newsgroups |
-			sed 's/^/  g	/g'
+			sed 's/^/  g	/g' |
+			eval $pager
 	case p
 		for(i in $r)
-			p $i
+			np $i
 	case P
 		for(i in $r)
 			P $i
@@ -291,6 +295,8 @@
 		cmd=`{echo $"cmd | sed 's/^\|//g'}
 		cat $mnt/$group/^$rposts($post)^/body | eval $cmd
 	case '?'
+		echo editor: $editor
+		echo pager: $pager
 		echo mnt: $mnt
 		echo group: $group
 		echo maxposts: $maxposts
@@ -302,12 +308,12 @@
 		echo r: $r
 	case *
 		if(~ $post $posts(1) && ~ $#go 0)
-			p $post
+			np $post
 		if not if(! ~ $post $posts($#posts)){
 			post=`{echo $post^+1 | bc}
 			if(test $post -gt $posts($#posts))
 				post=$posts($#posts)
-			p $post
+			np $post
 		}
 	}	
 }
--- a/sys/man/1/newt
+++ b/sys/man/1/newt
@@ -142,6 +142,12 @@
 .TP
 \fB"\fP
 Print the current message in quoted form, suitable for reply.
+.PP
+The environment variables
+.B $editor
+and
+.B $pager
+are honored.
 .SH FILES
 .B $home/lib/newsgroups
 list of newsgroups, one per line