dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 99de0d22d68c02958cbe8fae43aeff98e60c27e7
parent e8cea8b5956f1f3c186895b7b404cee0fa66d68a
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 27 Feb 2020 10:12:38 +0100

Handle gopher in search, add gopher bookmarks, allow search from X or terminal

Diffstat:
M.local/bin/plumb | 21+++++++++++++++++++--
M.local/bin/radio | 9++++++++-
A.local/bin/search | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D.local/bin/websearch | 46----------------------------------------------
4 files changed, 95 insertions(+), 49 deletions(-)

diff --git a/.local/bin/plumb b/.local/bin/plumb @@ -102,8 +102,25 @@ handle_target() { cd /tmp && detach comic "$t" elif regexmatch "$t" '10\.[0-9]*\/'; then detach $BROWSER "https://doi.org/${t}" - elif regeximatch "$t" '^gopher://'; then - detach $TERMINAL sacc "$t" + elif regeximatch "$t" '^gopher://' || \ + { regexmatch "$t" '^(0|1|3|7|9|g|I|h)' && \ + [ "$(printf '%s' "$t" | awk -F'\t' '{print NF}')" -eq 4 ]; }; then + + if [ "$(printf '%s' "$t" | awk -F'\t' '{print NF}')" -eq 4 ]; then + # construct uri from gopher item + type="$(printf '%s' "$t" | cut -c 1)" + path="$(printf '%s' "$t" | awk -F'\t' '{print $2}')" + host="$(printf '%s' "$t" | awk -F'\t' '{print $3}')" + port="$(printf '%s' "$t" | awk -F'\t' '{print $4}')" + t="${host}:${port}/${type}${path}" + fi + echo "$t" + + if [ -z "$TERM" ]; then + detach $TERMINAL sacc "$t" + else + sacc "$t" + fi elif regeximatch "$t" '^(http|https)://'; then detach $BROWSER "$t" else diff --git a/.local/bin/radio b/.local/bin/radio @@ -14,7 +14,14 @@ WBGO" lines=10 prompt="station: " -t="$(printf '%s' "$n" | imenu -i -l "$lines" -p "$prompt")" +if [ -z "$TERM" ]; then + t="$(printf '%s' "$n" | dmenu -i -l "$lines" -p "$prompt")" +else + t="$(printf '%s' "$n" | fzy -l "$lines" -p "$prompt")" +fi +if [ -z "$t" ]; then + exit 1 +fi case "$t" in bitreich) diff --git a/.local/bin/search b/.local/bin/search @@ -0,0 +1,68 @@ +#!/bin/sh + +if [ $# -lt 1 ]; then + uris="$(cat "$HOME"/doc/gopherbookmarks; \ + grep 'href="htt' "$HOME"/doc/bookmark.html | + sed 's/<\/.*>//g' | + sed 's/.*<a href="//;s/">/ /;s/<\/a>//'; + cat "$HOME"/doc/bookmark.txt)" + + lines=10 + prompt="search: " + if [ -z "$TERM" ]; then + c=$(printf '%s' "$uris" | dmenu -i -l "$lines" -p "$prompt") || exit 1 + else + c=$(printf '%s' "$uris" | fzy -l "$lines" -p "$prompt") || exit 1 + fi +else + c="$*" +fi + +regexmatch() { + printf '%s' "$1" | grep -E -q "$2" +} + +regeximatch() { + printf '%s' "$1" | grep -i -E -q "$2" +} + + +if regeximatch "$c" '^gopher://' || \ + { regexmatch "$c" '^(0|1|3|7|9|g|I|h)' && \ + [ "$(printf '%s' "$c" | awk -F'\t' '{print NF}')" -eq 4 ]; }; then + echo "this is gopher" + plumb "$c" + +elif regeximatch "$c" '^(http|https)://'; then + plumb "$(printf '%s' "$c" | awk '{print $1}')" + +elif regeximatch "$c" '!scholar'; then + plumb "https://scholar.google.com/scholar?q=$(printf '%s' "$c" | sed 's/ *!scholar *//')" + +elif regeximatch "$c" '!map'; then + plumb "https://www.openstreetmap.org/search?query=$(printf '%s' "$c" | sed 's/ *!map *//')" + +elif regeximatch "$c" '!wiki'; then + plumb "https://en.wikipedia.org/wiki/Special:Search?search=$(printf '%s' "$c" | sed 's/ *!wiki *//')" + +elif regeximatch "$c" '!yt'; then + idiotbox="$HOME/code/idiotbox" + q="$(printf '%s' "$c" | sed "s/ *!yt *//")" + if [ -x "$idiotbox/cgi" ]; then + tmpfile=/tmp/yt.html + QUERY_STRING="q=$(printf '%s' "$q" | tr ' ' '+')" \ + "$idiotbox/cgi" > "$tmpfile" + cp -r "$idiotbox/css" /tmp + plumb "$tmpfile" + sleep 5 + rm "$tmpfile" + else + plumb "https://codemadness.org/idiotbox/?q=${q}&o=relevance&m=Dark" + fi + +elif regexmatch "$c" ' '; then + plumb "https://duckduckgo.com/?q=$(printf '%s' "$c" | sed 's/+/%2b/g')&kae=d&kau=-1&kao=-1&kap=-1&kaq=-1&kax=-1&kak=-1&kv=-1&kk=-1&k1=-1&kc=-1" + +else + plumb "http://${c}" +fi diff --git a/.local/bin/websearch b/.local/bin/websearch @@ -1,46 +0,0 @@ -#!/bin/sh - -if [ $# -lt 1 ]; then - url="$(grep 'href="htt' "$HOME"/doc/bookmark.html | \ - sed 's/<\/.*>//g' | \ - sed 's/.*<a href="//;s/">/ /;s/<\/a>//' ; - cat ~/doc/bookmark.txt)" - - choice=$(printf '%s' "$url" | dmenu -i -p "search:") || exit 1 -else - choice="$*" -fi - -# Detect if url -case "$choice" in - http://*|https://*) - plumb "$(printf '%s' "$choice" | awk '{print $1}')" - ;; - *!scholar*) - plumb "https://scholar.google.com/scholar?q=$(printf '%s' "$choice" | sed 's/!scholar//')" - ;; - *!map*) - plumb "https://www.openstreetmap.org/search?query=$(printf '%s' "$choice" | sed 's/!map//')" - ;; - *!wiki*) - plumb "https://en.wikipedia.org/wiki/Special:Search?search=$(printf '%s' "$choice" | sed 's/!wiki//')" - ;; - *!yt*) - idiotbox="$HOME/code/idiotbox" - if [ -x "$idiotbox/cgi" ]; then - tmpfile=/tmp/yt.html - QUERY_STRING="q=$(printf '%s' "$choice" | sed "s/!yt//" | tr ' ' '+')" \ - "$idiotbox/cgi" > "$tmpfile" - cp -r "$idiotbox/css" /tmp - plumb "$tmpfile" - sleep 5 - rm "$tmpfile" - else - plumb "https://codemadness.org/idiotbox/?q=$(printf '%s' "$choice" | sed 's/!yt//')&o=relevance&m=Dark" - fi - ;; - *\ *) - plumb "https://duckduckgo.com/?q=$(printf '%s' "$choice" | sed 's/+/%2b/g')&kae=d&kau=-1&kao=-1&kap=-1&kaq=-1&kax=-1&kak=-1&kv=-1&kk=-1&k1=-1&kc=-1";; - *) - plumb "http://${choice}";; -esac