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 d0a8ba924bd054f577012cc7bd245a8ed75bacdd
parent 5b48481f84d2609e41c33295ea676e2941ff14c3
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 19 Feb 2020 09:24:35 +0100

Rewrite to posix sh

Diffstat:
M.local/bin/websearch | 70++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 34 insertions(+), 36 deletions(-)

diff --git a/.local/bin/websearch b/.local/bin/websearch @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh if [ $# -lt 1 ]; then url="$(grep 'href="htt' "$HOME"/doc/bookmark.html | \ @@ -6,42 +6,40 @@ if [ $# -lt 1 ]; then sed 's/.*<a href="//;s/">/ /;s/<\/a>//' ; cat ~/doc/bookmark.txt)" - choice=$(echo "$url" | dmenu -i -p "search:") || exit 1 + choice=$(printf '%s' "$url" | dmenu -i -p "search:") || exit 1 else - choice="$@" + choice="$*" fi # Detect if url -if [[ "$choice" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9\-]+\.[a-zA-Z]+(/)?.*$ ]]; then - $BROWSER "$(echo "$choice" | awk '{print $1}')" -else - case "$choice" in - *!scholar*) - $BROWSER "https://scholar.google.com/scholar?q=${choice/!scholar/}" - ;; - *!map*) - $BROWSER "https://www.openstreetmap.org/search?query=${choice/!map/}" - ;; - *!wiki*) - $BROWSER "https://en.wikipedia.org/wiki/Special:Search?search=${choice/!wiki/}" - ;; - *!yt*) - idiotbox="$HOME/code/idiotbox" - if [ -x "$idiotbox/cgi" ]; then - tmpfile=/tmp/yt.html - QUERY_STRING="q=$(printf '%s' "${choice/!yt/}" | tr ' ' '+')" \ - "$idiotbox/cgi" > "$tmpfile" - cp -r "$idiotbox/css" /tmp - $BROWSER "$tmpfile" - sleep 5 - rm "$tmpfile" - else - $BROWSER "https://codemadness.org/idiotbox/?q=${choice/!yt/}&o=relevance&m=Dark" - fi - ;; - *) - $BROWSER "https://duckduckgo.com/?q=$(echo $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" - ;; - esac - fi -fi +case "$choice" in + http://*|https://) + $BROWSER "$(printf '%s' "$choice" | awk '{print $1}')" + ;; + *!scholar*) + $BROWSER "https://scholar.google.com/scholar?q=$(printf '%s' "$choice" | sed 's/!scholar//')" + ;; + *!map*) + $BROWSER "https://www.openstreetmap.org/search?query=$(printf '%s' "$choice" | sed 's/!map//')" + ;; + *!wiki*) + $BROWSER "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 + $BROWSER "$tmpfile" + sleep 5 + rm "$tmpfile" + else + $BROWSER "https://codemadness.org/idiotbox/?q=$(printf '%s' "$choice" | sed 's/!yt//')&o=relevance&m=Dark" + fi + ;; + *) + $BROWSER "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" + ;; +esac