shithub: wpq

Download patch

ref: 106dc1fb2e83656cff5b9e4565bba0be2ef68d45
parent: fac705ddaf2ae19afd8d1791c0c94cfc696c03e2
author: rodri <rgl@antares-labs.eu>
date: Sat Mar 8 14:38:00 EST 2025

wpq: improve and clean up.

there's no need to create a temporary file.

--- a/wpq
+++ b/wpq
@@ -1,32 +1,32 @@
 #!/bin/rc
 rfork e
 ts=`{date -n}
-tmpfile=/tmp/wpsearch.$ts
 wanthtml=n
 
-fn sigint {
-	rm -f $tmpfile
-}
-
 fn usage {
 	echo usage: $0 [-h] query >[1=2]
 	exit usage
 }
 
+fn mkurl {
+	echo -n '{"result":'
+	hget 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search='^$"*
+	echo -n '}'
+}
+
 if(~ $#* 0)
 	usage
+
 switch($1){
 case -*h*
 	wanthtml=y
 	shift
 }
-{
-	echo -n '{"result":'
-	hget 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search='^$"*
-	echo -n '}'
-} >$tmpfile
-targ=`{wpqprompt $tmpfile | tr ' ' '_'}
-rm -f $tmpfile
+
+targ=`{wpqprompt <{mkurl $*} | tr ' ' '_'}
+if(~ $#targ 0)
+	exit
+
 if(~ $wanthtml y)
 	plumb 'https://en.wikipedia.org/wiki/'^$targ
 if not
--