commit d195ecc2648dc74c89e96ed15110ef3dffe19724
parent 09bfa9364cdb0ab17db10c4417bb62cd0f90a173
Author: Oliver Lowe <o@olowe.co>
Date: Mon, 16 Sep 2024 16:48:45 +1000
add web search program
Diffstat:
3 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/README b/README
@@ -10,4 +10,5 @@ The following commands are provided:
- lemmyverse - find lemmy communities
- llama - prompt a large language model
- webpaste - create a web paste on webpaste.olowe.co
+- ws - web search
- xstream - stream X display over the network
diff --git a/bin/ws b/bin/ws
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+firefox="Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0"
+
+prog='
+/duckduckgo.com\/y.js/ { next } # skip ads
+/Sponsored link/ { next } # skip ads
+/result-link/ {
+ $1=$1
+ link = substr($3, index($3, "\""), length($3))
+ link = substr(link, 2, length(link)-2)
+
+ title = substr($0, index($0, ">")+1, length)
+ title = substr(title, 1, index(title, "<")-1)
+ print link
+ print "\t" title
+}
+'
+
+curl -s -d "q=$@" -H "User-Agent: $firefox" https://lite.duckduckgo.com/lite/ | awk "$prog"
diff --git a/man/ws.1 b/man/ws.1
@@ -0,0 +1,38 @@
+.Dd
+.Dt WS 1
+.Sh NAME
+.Nm ws
+.Nd web search
+.Sh SYNOPSIS
+.Nm
+.Ar query ...
+.Sh DESCRIPTION
+.Nm
+sends the query to a web search engine
+.Pq default DuckDuckGo
+and prints the results to the standard output.
+.Sh EXAMPLE
+.Pp
+Find the Plan 9 Foundation home page:
+.Dl ws Plan 9 foundation
+.Pp
+Search the web for motorcycle parts for
+Yamaha's discontinued dual-sport motorcycle:
+.Bd -literal -offset Ds
+ws '"wr250r parts"' Australia
+.Ed
+.Pp
+The first two keywords are quoted
+to include search results containing both
+.Dq wr250r
+and
+.Dq parts .
+This is again enclosed in single quotes to ensure
+.Xr sh 1
+does not interpret its own quote characters.
+.Sh EXIT STATUS
+.Ex
+.Sh SEE ALSO
+.Xr curl 1 ,
+.Xr awk 1 ,
+.Lk https://duckduckgo.com/duckduckgo-help-pages/features/non-javascript/ How To Use the Non-JavaScript Version of DuckDuckGo Search