aboutsummaryrefslogtreecommitdiff
path: root/local
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2017-10-18 10:56:40 +0200
committerKarel Kočí <karel.koci@nic.cz>2017-10-18 10:56:40 +0200
commit7ca61f073f215214bcd997408a8a4b4b0c37705e (patch)
tree8a600fb288d25e0f9134a9e0aab7d0c32e84dd0c /local
parentef44451e7a7a60ec2c6382f811f709fa5686c2a2 (diff)
downloadmyconfigs-7ca61f073f215214bcd997408a8a4b4b0c37705e.tar.gz
myconfigs-7ca61f073f215214bcd997408a8a4b4b0c37705e.tar.bz2
myconfigs-7ca61f073f215214bcd997408a8a4b4b0c37705e.zip
Add surf configuration
Diffstat (limited to 'local')
-rwxr-xr-xlocal/bin/surf-menu43
1 files changed, 43 insertions, 0 deletions
diff --git a/local/bin/surf-menu b/local/bin/surf-menu
new file mode 100755
index 0000000..bd13e6b
--- /dev/null
+++ b/local/bin/surf-menu
@@ -0,0 +1,43 @@
+#!/bin/sh
+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
+
+ surf "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web"
+
+ 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#^[^/]\+/\?##')"
+
+ # Try to lookup if it's an real address
+ # Note: This is hack because of youtube, nslookup return No answer but
+ # exists with 0. So I am checking if it returned more than one address
+ # (one address is for dns server).
+ if [ "$(nslookup "$LHOST" | grep 'Address:' | wc -l)" -le 1 ]; then # It's a real address
+ if nslookup "$LHOST.cz" >/dev/null; then # we can expand it with cz
+ LHOST="$LHOST.cz"
+ elif nslookup "$LHOST.com" >/dev/null; then # we can expand it with com
+ 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" & # run backgrounded
+
+ fi
+
+done