From e908c03fe775787c048ead719220e64b5af8bfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Fri, 20 Oct 2017 18:10:08 +0200 Subject: Update surf configuration --- local/bin/surf-menu | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'local/bin/surf-menu') diff --git a/local/bin/surf-menu b/local/bin/surf-menu index bd13e6b..f4925f8 100755 --- a/local/bin/surf-menu +++ b/local/bin/surf-menu @@ -3,17 +3,27 @@ set -e BOOKMARDS=~/notes/bookmarks.md -# Note: Bookmarks starts with '* ' -sed -n 's/\* //p' "$BOOKMARDS" | dmenu -p 'surf' | while read L; do - if echo "$L" | grep -qE '^\?'; then # We do search on duckduckgo +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" + surf "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web" & + + elif echo "$1" | grep -qE '^~?/'; then # This is local path + + surf "${1/#\~/$HOME}" & + + elif echo "$1" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'; then # This ipv4 address + + surf "$1" & else # We follow address - LPROTOCOL="$(echo "$L" | sed -n 's#^\([^:]*\)://.*#\1#p')" - LHOST="$(echo "$L" | sed -n 's#^[^:]*://##;s#^\([^/]\+\)/\?.*#\1#p')" - LPATH="$(echo "$L" | sed 's#^[^:]*://##;s#^[^/]\+/\?##')" + LPROTOCOL="$(echo "$1" | sed -n 's#^\([^:]*\)://.*#\1#p')" + LHOST="$(echo "$1" | sed -n 's#^[^:]*://##;s#^\([^/]\+\)/\?.*#\1#p')" + LPATH="$(echo "$1" | sed 's#^[^:]*://##;s#^[^/]\+/\?##')" # Try to lookup if it's an real address # Note: This is hack because of youtube, nslookup return No answer but @@ -36,8 +46,17 @@ sed -n 's/\* //p' "$BOOKMARDS" | dmenu -p 'surf' | while read L; do fi fi - surf "$LPROTOCOL://$LHOST/$LPATH" & # run backgrounded + surf "$LPROTOCOL://$LHOST/$LPATH" & fi - -done +} + +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 +fi -- cgit v1.2.3