summaryrefslogtreecommitdiff
path: root/surf-menu
diff options
context:
space:
mode:
Diffstat (limited to 'surf-menu')
-rwxr-xr-xsurf-menu77
1 files changed, 77 insertions, 0 deletions
diff --git a/surf-menu b/surf-menu
new file mode 100755
index 0000000..7b31f13
--- /dev/null
+++ b/surf-menu
@@ -0,0 +1,77 @@
+#!/bin/sh
+set -e
+
+# For wayland
+# Surf is unable to run under wayland. This overcomes that and forces it to use
+# xwayland instead.
+export GDK_BACKEND=x11
+
+BOOKMARDS=~/notes/bookmarks.md
+#HISTORY=~/notes/.surf_history # TODO history
+SOCKS_PROXY="socks://localhost:8123"
+
+open_uri() {
+ if [ -n "$xid" ]; then
+ xprop -id "$xid" -f "_SURF_GO" 8s -set "_SURF_GO" "$1"
+ else
+ surf "$1" &
+ fi
+}
+
+xid=""
+addch=""
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -h|--h)
+ echo "This is menu script for surf web browser."
+ echo "Usage: $0 [OPTION]..."
+ echo
+ echo "Options:"
+ echo " --help, -h"
+ echo " Print this help text."
+ echo " --xid XID"
+ echo " Instead of opening new surf instance set url to existing one"
+ echo " --socks"
+ echo " Use SOCKS proxy"
+ exit
+ ;;
+ --xid)
+ xid="$2"
+ shift
+ ;;
+ -a|--add)
+ shift
+ addch="$addch
+$1"
+ ;;
+ --socks)
+ export ALL_PROXY="$SOCKS_PROXY"
+ export http_proxy="$SOCKS_PROXY"
+ export https_proxy="$SOCKS_PROXY"
+ ;;
+ *)
+ echo "Unknown option $1" >&2
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+# If xid is given then as first one add current uri
+if [ -n "$xid" ]; then
+ addch="$(xprop -id "$xid" _SURF_URI | sed -n 's/.*(STRING) = "\(.*\)"/\1/p')"
+ dmenu_args="-w $xid -p Go:"
+fi
+
+# Note: Bookmarks starts with '* '
+choose="$addch
+$(sed -n 's/\* //p' "$BOOKMARDS")"
+
+echo "$choose" | sed '/^\s*$/d' | dmenu -p 'surf' $dmenu_args | while read L; do
+ if echo "$L" | grep -qE '^\?'; then # We do search on duckduckgo
+ open_uri "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web"
+ else
+ open_uri "$L"
+ fi
+done