From 4dfc020240646cd5990086d74c02cf710338baa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 3 Dec 2017 13:40:21 +0100 Subject: Add ability to specify xid to surf-menu --- surf-menu | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/surf-menu b/surf-menu index b2e0111..59dcc30 100755 --- a/surf-menu +++ b/surf-menu @@ -2,22 +2,31 @@ set -e BOOKMARDS=~/notes/bookmarks.md +# TODO history +#HISTORY=~/notes/.surf_history + +set_uri() { + if [ -n "$XID" ]; then + xprop -id "$XID" -f "_SURF_GO" 8s -set "_SURF_GO" "$1" + else + surf "$1" & + fi +} run() { - echo "Run $1" - echo "$1" | grep -qE '^~?/' || true - echo $? if echo "$1" | grep -qE '^\?'; then # We do search on duckduckgo - surf "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web" & + set_uri "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web" elif echo "$1" | grep -qE '^~?/'; then # This is local path - surf "${1/#\~/$HOME}" & + set_uri "${1/#\~/$HOME}" elif echo "$1" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'; then # This ipv4 address - surf "$1" & + set_uri "$1" + + # TODO ipv6 address else # We follow address @@ -44,17 +53,53 @@ run() { fi fi - surf "$LPROTOCOL://$LHOST/$LPATH" & + set_uri "$LPROTOCOL://$LHOST/$LPATH" fi } -if [ -n "$1" ]; then - run "$1" - exit -else - # Note: Bookmarks starts with '* ' - sed -n 's/\* //p' "$BOOKMARDS" | dmenu -p 'surf' | while read L; do - run "$L" - done +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" + exit + ;; + --xid) + XID="$2" + shift + ;; + -a|--add) + shift + ADDCH="$ADDCH +$1" + ;; + *) + 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 's/.*= "\(.*\)"/\1/')" fi + +# Note: Bookmarks starts with '* ' +CHOOSE="$ADDCH +$(sed -n 's/\* //p' "$BOOKMARDS")" + +echo "$CHOOSE" | sed '/^\s*$/d' | dmenu -p 'surf' | while read L; do + run "$L" +done -- cgit v1.2.3