blob: 7b31f1341648d288a75d7c0b3797296a27714476 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#!/bin/sh
set -e
# For wayland
# Surf is unable to run under wayland. This overcomes that and forces it to use
# xwayland instead.
export GDK_BACKEND=x11
BOOKMARDS=~/notes/bookmarks.md
#HISTORY=~/notes/.surf_history # TODO history
SOCKS_PROXY="socks://localhost:8123"
open_uri() {
if [ -n "$xid" ]; then
xprop -id "$xid" -f "_SURF_GO" 8s -set "_SURF_GO" "$1"
else
surf "$1" &
fi
}
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"
echo " --socks"
echo " Use SOCKS proxy"
exit
;;
--xid)
xid="$2"
shift
;;
-a|--add)
shift
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
;;
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 -n 's/.*(STRING) = "\(.*\)"/\1/p')"
dmenu_args="-w $xid -p Go:"
fi
# Note: Bookmarks starts with '* '
choose="$addch
$(sed -n 's/\* //p' "$BOOKMARDS")"
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
|