diff options
author | Karel Kočí <cynerd@email.cz> | 2017-12-03 13:40:21 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-12-03 13:40:21 +0100 |
commit | 4dfc020240646cd5990086d74c02cf710338baa8 (patch) | |
tree | 56d3d0c19893bb05602e141dbf15b01b062f6a5e | |
parent | 1e56cb0c4b1b7dd97ecd2ad2eab62883883c0187 (diff) | |
download | surf-107632b4f20f7471c6c3e3db30e28c2d3e0f07cb.tar.gz surf-107632b4f20f7471c6c3e3db30e28c2d3e0f07cb.tar.bz2 surf-107632b4f20f7471c6c3e3db30e28c2d3e0f07cb.zip |
Add ability to specify xid to surf-menuv2.0.1
-rwxr-xr-x | surf-menu | 75 |
1 files changed, 60 insertions, 15 deletions
@@ -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 |