diff options
author | Karel Kočí <cynerd@email.cz> | 2017-12-03 13:18:06 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-12-03 13:19:44 +0100 |
commit | 1e56cb0c4b1b7dd97ecd2ad2eab62883883c0187 (patch) | |
tree | 239812cfab3694b25ce6179a884b65af69398b6e | |
parent | 28abfddf9b425fb141e5d3ddd7968f9852e1fd52 (diff) | |
download | surf-1e56cb0c4b1b7dd97ecd2ad2eab62883883c0187.tar.gz surf-1e56cb0c4b1b7dd97ecd2ad2eab62883883c0187.tar.bz2 surf-1e56cb0c4b1b7dd97ecd2ad2eab62883883c0187.zip |
Add current version of surf menu
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | surf-menu | 60 |
2 files changed, 63 insertions, 0 deletions
@@ -52,6 +52,9 @@ install: all @mkdir -p $(DESTDIR)$(PREFIX)/bin @cp -f surf $(DESTDIR)$(PREFIX)/bin @chmod 755 $(DESTDIR)$(PREFIX)/bin/surf + @echo installing surf-menu to $(DESTDIR)$(PREFIX)/bin + @cp -f surf-menu $(DESTDIR)$(PREFIX)/bin + @chmod 755 $(DESTDIR)$(PREFIX)/bin/surf-menu @echo installing manual page to $(DESTDIR)$(MANPREFIX)/man1 @mkdir -p $(DESTDIR)$(MANPREFIX)/man1 @sed "s/VERSION/$(VERSION)/g" < surf.1 > $(DESTDIR)$(MANPREFIX)/man1/surf.1 diff --git a/surf-menu b/surf-menu new file mode 100755 index 0000000..b2e0111 --- /dev/null +++ b/surf-menu @@ -0,0 +1,60 @@ +#!/bin/sh +set -e + +BOOKMARDS=~/notes/bookmarks.md + +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" & + + 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 "$1" | sed -n 's#^\([^:]*\)://.*#\1#p')" + LHOST="$(echo "$1" | sed -n 's#^[^:]*://##;s#^\([^/]\+\)/\?.*#\1#p')" + LPATH="$(echo "$1" | sed 's#^[^:]*://##;s#^[^/]\+/\?##')" + + if ! getent hosts "$LHOST" >/dev/null; then + if getent hosts "$LHOST.cz" >/dev/null; then + LHOST="$LHOST.cz" + elif getent hosts "$LHOST.org" >/dev/null; then + LHOST="$LHOST.org" + elif getent hosts "$LHOST.com" >/dev/null; then + LHOST="$LHOST.com" + fi + # TODO what to do when we can't expand it? + fi + # Decide on protocol (if connection to 443 is not possible then use http otherwise https) + if [ -z "$LPROTOCOL" ]; then # We already have protocol (given explicitly) + if nc -z -w1 "$LHOST" 443 2>/dev/null; then + LPROTOCOL="https" + else + LPROTOCOL="http" + fi + fi + + surf "$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 +fi |