summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2019-02-09 15:37:32 +0100
committerKarel Kočí <cynerd@email.cz>2019-02-09 15:37:32 +0100
commitefc49f30352636d72095703058bf4983f012235f (patch)
tree8489b0ebea463b87a751ee73ab28eff608bf11e5
parent93c8bc83c581c4e88c90359fa527d6f867600f65 (diff)
downloadsurf-efc49f30352636d72095703058bf4983f012235f.tar.gz
surf-efc49f30352636d72095703058bf4983f012235f.tar.bz2
surf-efc49f30352636d72095703058bf4983f012235f.zip
surf-menu; drop server detection and add SOCKS
-rwxr-xr-xsurf-menu88
1 files changed, 27 insertions, 61 deletions
diff --git a/surf-menu b/surf-menu
index 8084d05..7b31f13 100755
--- a/surf-menu
+++ b/surf-menu
@@ -7,64 +7,19 @@ set -e
export GDK_BACKEND=x11
BOOKMARDS=~/notes/bookmarks.md
-# TODO history
-#HISTORY=~/notes/.surf_history
+#HISTORY=~/notes/.surf_history # TODO history
+SOCKS_PROXY="socks://localhost:8123"
-set_uri() {
- if [ -n "$XID" ]; then
- xprop -id "$XID" -f "_SURF_GO" 8s -set "_SURF_GO" "$1"
+open_uri() {
+ if [ -n "$xid" ]; then
+ xprop -id "$xid" -f "_SURF_GO" 8s -set "_SURF_GO" "$1"
else
surf "$1" &
fi
}
-run() {
- if echo "$1" | grep -qE '^\?'; then # We do search on duckduckgo
-
- set_uri "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web"
-
- elif echo "$1" | grep -qE '^~?/'; then # This is local path
-
- set_uri "${1/#\~/$HOME}"
-
- elif echo "$1" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'; then # This ipv4 address
-
- set_uri "$1"
-
- # TODO ipv6 address
-
- 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
-
- set_uri "$LPROTOCOL://$LHOST/$LPATH"
-
- fi
-}
-
-XID=""
-ADDCH=""
+xid=""
+addch=""
while [ $# -gt 0 ]; do
case "$1" in
@@ -77,17 +32,24 @@ while [ $# -gt 0 ]; do
echo " Print this help text."
echo " --xid XID"
echo " Instead of opening new surf instance set url to existing one"
+ echo " --socks"
+ echo " Use SOCKS proxy"
exit
;;
--xid)
- XID="$2"
+ xid="$2"
shift
;;
-a|--add)
shift
- ADDCH="$ADDCH
+ addch="$addch
$1"
;;
+ --socks)
+ export ALL_PROXY="$SOCKS_PROXY"
+ export http_proxy="$SOCKS_PROXY"
+ export https_proxy="$SOCKS_PROXY"
+ ;;
*)
echo "Unknown option $1" >&2
exit 1
@@ -96,16 +58,20 @@ $1"
shift
done
-# If XID is given then as first one add current uri
-if [ -n "$XID" ]; then
- ADDCH="$(xprop -id "$XID" _SURF_URI | sed -n 's/.*(STRING) = "\(.*\)"/\1/p')"
- DMENU_ARGS="-w $XID -p Go:"
+# If xid is given then as first one add current uri
+if [ -n "$xid" ]; then
+ addch="$(xprop -id "$xid" _SURF_URI | sed -n 's/.*(STRING) = "\(.*\)"/\1/p')"
+ dmenu_args="-w $xid -p Go:"
fi
# Note: Bookmarks starts with '* '
-CHOOSE="$ADDCH
+choose="$addch
$(sed -n 's/\* //p' "$BOOKMARDS")"
-echo "$CHOOSE" | sed '/^\s*$/d' | dmenu -p 'surf' $DMENU_ARGS | while read L; do
- run "$L"
+echo "$choose" | sed '/^\s*$/d' | dmenu -p 'surf' $dmenu_args | while read L; do
+ if echo "$L" | grep -qE '^\?'; then # We do search on duckduckgo
+ open_uri "https://duckduckgo.com/?q=${L#?}&t=surf&kk=-1&ia=web"
+ else
+ open_uri "$L"
+ fi
done