/
dmenu-url
executable file
·72 lines (66 loc) · 1.83 KB
/
dmenu-url
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
#!/bin/sh
# save/list recent user entered url via dmenu
# surf send current url as input
# and -p Go: or Find: in cmdline
# and -w wid (windowid)
#
[ -f ~/.surf/config ] && . ~/.surf/config
last=""
while getopts ":p:w:u:" opt; do
case $opt in
p)
DMOPT=${OPTARG%:}
if [ "$DMOPT" = "Go" ]; then
recentFile="${recent_dir:-$HOME/.local/share}/recent_url"
else
recentFile="${recent_dir:-$HOME/.local/share}/recent_sfind"
fi
;;
w)
wid=$OPTARG
# clsname is surf filename; running sym link can use different recentFile
clsname=$(xprop -id $wid WM_CLASS | cut -d '=' -f 2 | cut -d ',' -f 1 | xargs)
if [ "$clsname" != "surf" ]; then
recentFile="${recentFile}.$clsname"
fi
;;
u)
last=$OPTARG
;;
\?)
#echo "ignore option: -$OPTARG"
/usr/bin/dmenu "$@"
exit
;;
:)
echo "option: -$OPTARG requires argument"
exit 1
;;
esac
done
if [ ! -n "$last" ]; then
while read -r line || [ -n "$line" ] ;
do
last="$line"
done
fi
if [ -n "$last" ]; then
last=${last#http*://}
fi
if [ ! -f "$recentFile" ]; then
touch "$recentFile"
fi
sel=$(echo "$last" | cat - "$recentFile" | rofi -dmenu -p "$DMOPT")
if [ "$sel" != "" ]; then
insert-rec "$sel" "$recentFile"
# search if not url
if [ "$DMOPT" = "Go" ] && [ "$search_q" != "" ] && [ "$sel" = "${sel#/}" ]; then
if [ "$sel" = "${sel#http*://}" ] && [ "$sel" = "${sel#localhost}" ]; then
echo "$sel" | cut -d '/' -f 1 | grep -q -P "(?=^.{4,253}$)(^(?:[a-zA-Z0-9](?:(?:[a-zA-Z0-9\-]){0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$)"
if [ $? -gt 0 ]; then
sel="$search_q$sel"
fi
fi
fi
fi
echo -n "$sel"