summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-12-03 13:40:21 +0100
committerKarel Kočí <cynerd@email.cz>2017-12-03 13:40:21 +0100
commit4dfc020240646cd5990086d74c02cf710338baa8 (patch)
tree56d3d0c19893bb05602e141dbf15b01b062f6a5e
parent1e56cb0c4b1b7dd97ecd2ad2eab62883883c0187 (diff)
downloadsurf-2.0.1.tar.gz
surf-2.0.1.tar.bz2
surf-2.0.1.zip
Add ability to specify xid to surf-menuv2.0.1
-rwxr-xr-xsurf-menu75
1 files 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