dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

srxsrch (1716B)


      1 #!/bin/sh
      2 
      3 location=/exec/srxsrch.dcgi
      4 instance=searx.sunless.cloud
      5 
      6 # this script works both as a gopher frontend & cmdline frontend
      7 [ -z $1 ] 2>/dev/null && echo "usage: srxsrch <query> [page]" && exit 1
      8 #
      9 # gopher: [7|srxsrch|searx.dcgi|server|port]
     10 # gopher: [7|srxsrch|searx.dcgi?page|server|port]
     11 #                              ^^^^^
     12 # gopher: [1|srxsrch|searx.dcgi?page:query|server|port]
     13 #                              ^^^^^^^^^^^
     14 # will generate links if it can find env variables for geomyidae
     15 # eg: search again, next page, and http links
     16 
     17 echo "$2" | grep ':' >/dev/null && {
     18 	query=${2##*:}
     19 	page=${2%%:*}
     20 } || {
     21 	query="$1"
     22 	page="${2:-1}"
     23 }
     24 
     25 gopherize(){
     26 	[ "$SERVER_PROTOCOL" = "gopher/1.0" ] && {
     27 		echo "[7|Search again|$location|server|port]"
     28 		echo "[1|Next page|$location?$(($page+1)):$query|server|port]"
     29 		echo
     30 		tr '|\n' ':\t' | sed -E 's~\t(\[[0-9]*\])~\n\1~g' | awk -F"	" '{printf("[h|%s %s|URL:%s|server|port]\n%s\n\n", $1, $3, $2, $4)}'
     31 		echo
     32 		echo "[1|Next page|$location?$(($page+1)):$query|server|port]"
     33 		echo "[7|Search again|$location|server|port]"
     34 		echo "Powered by searx at http://$instance"
     35 	} || cat
     36 }
     37 
     38 dorecode(){
     39 	command -v recode >/dev/null && recode html.. || cat
     40 }
     41 
     42 curl -H "Accept-Language: en-US" -qsL "https://$instance/?q=$(echo "$query" | xxd -p | tr -d '\n' | sed 's/../%&/g')&pageno=$page" \
     43 	| grep '<div class="result' | sed -E '
     44 		s~<[^>]*><[^>]*id="result-([0-9]*)">~[\1] ~;
     45 		s~<a href="([^"]*)"~\n'"$(tput setaf 9)\1$(tput sgr0)"'~;
     46 		s~ rel="noreferrer"[^>]*>~\n~;
     47 		s~</a></h4><p class="result-content">~\n~;
     48 		s~</p><div class="clearfix".*~\n~;
     49 		s~<span class="highlight">~'"$(tput bold)~g;
     50 		s~</span>~$(tput sgr0)~g" | dorecode | gopherize | less -R