summaryrefslogtreecommitdiff
path: root/.uzbl/scripts/load_url_from_surfraw.sh
diff options
context:
space:
mode:
authorUrbain Vaes <urbain@vaes.uk>2015-09-15 10:47:10 +0100
committerUrbain Vaes <urbain@vaes.uk>2015-09-15 10:47:10 +0100
commite15acb86050ff4e90441a9f5772b1f985fd944cf (patch)
tree9e09930e368f8ace79f9089e21851028cecf99c1 /.uzbl/scripts/load_url_from_surfraw.sh
parentb4258ad041b8e0c8102e57e662970c6c3afe56a6 (diff)
parent9b7c7320d7926c4d8aaa8b68bb677114b292aa6a (diff)
Merge branch 'master' of github.com:uvaes/dotfiles
Conflicts: .uzbl/bookmarks .uzbl/config
Diffstat (limited to '.uzbl/scripts/load_url_from_surfraw.sh')
-rwxr-xr-x.uzbl/scripts/load_url_from_surfraw.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/.uzbl/scripts/load_url_from_surfraw.sh b/.uzbl/scripts/load_url_from_surfraw.sh
new file mode 100755
index 0000000..641ca3c
--- /dev/null
+++ b/.uzbl/scripts/load_url_from_surfraw.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# Default search engine. If we really are at a loss, use this
+DEFAULT_SEARCH=google
+
+# The location of the surfraw bookmark file
+BOOKMARKS="$HOME/.surfraw.bookmarks"
+
+# Colors for dmenu
+COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030"
+
+# Prompt for dmenu
+PROMPT="Open"
+
+# Use surfraw to search for the words
+function search()
+{
+ # Does surfraw know what to do with it?
+ url=`surfraw -print $@`
+
+ # If not, then use the default search engine
+ if [ $? -ne 0 ]
+ then
+ url=`surfraw -print $DEFAULT_SEARCH $@`
+ fi
+
+ echo $url
+}
+
+# We assume that this is a URL
+function goto()
+{
+ case "$1" in
+ *:*) echo $1 ;;
+ *) echo "http://$1" ;;
+ esac
+}
+
+# Use dmenu to navigate through possible choices
+function present_menu()
+{
+ elvi=`surfraw -elvi | cut -f 1 | tail --lines=+2`
+ if [ -r "$BOOKMARKS" ]
+ then
+ bookmarks=" `cut -f 1 -d ' ' "$BOOKMARKS" 2>/dev/null`"
+ else
+ bookmarks=""
+ fi
+
+ echo "${elvi}${bookmarks}" | tr ' ' '\n' | sort | dmenu -p "$PROMPT" -i $COLORS
+}
+
+present_menu | \
+ ( read car cdr
+test -z "$car" && exit 1
+( test -z "$cdr" && echo $car | fgrep -c '.
+:' > /dev/null && goto $car ) || search "$car $cdr" )