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

ducksearch (1293B)


      1 #!/usr/bin/env bash
      2 
      3 if [ $# -lt 1 ]; then
      4 	url="$(grep 'href="htt' "$HOME"/doc/bookmark.html | \
      5 		sed 's/<\/.*>//g' | \
      6 		sed 's/.*<a href="//;s/">/ /;s/<\/a>//' ;
      7 		cat ~/doc/bookmark.txt)"
      8 
      9 	choice=$(echo "$url" | dmenu -i -p "search:") || exit 1
     10 else
     11 	choice="$@"
     12 fi
     13 
     14 # Detect if url
     15 if [[ "$choice" =~ ^(http:\/\/|https:\/\/)?[a-zA-Z0-9\-]+\.[a-zA-Z]+(/)?.*$ ]]; then
     16 	$BROWSER "$(echo "$choice" | awk '{print $1}')"
     17 else
     18 	case "$choice" in
     19 		*!scholar*)
     20 			$BROWSER "https://scholar.google.com/scholar?q=${choice/!scholar/}"
     21 			;;
     22 		*!map*)
     23 			$BROWSER "https://www.openstreetmap.org/search?query=${choice/!map/}"
     24 			;;
     25 		*!wiki*)
     26 			$BROWSER "https://en.wikipedia.org/wiki/Special:Search?search=${choice/!wiki/}"
     27 			;;
     28 		*!yt*)
     29 			idiotbox="$HOME/code/idiotbox"
     30 			if [ -x "$idiotbox/cgi" ]; then
     31 				tmpfile=/tmp/yt.html
     32 				QUERY_STRING="q=$(printf '%s' "${choice/!yt/}" | tr ' ' '+')" \
     33 					"$idiotbox/cgi" > "$tmpfile"
     34 				cp -r "$idiotbox/css" /tmp
     35 				$BROWSER "$tmpfile"
     36 				sleep 1
     37 				rm "$tmpfile"
     38 			else
     39 				$BROWSER "https://codemadness.org/idiotbox/?q=${choice/!yt/}&o=relevance&m=Dark"
     40 			fi
     41 			;;
     42 		*)
     43 			$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"
     44 			;;
     45 		esac
     46 	fi
     47 fi