blob: cff09fc22242c24c98421b1ae5d1680dbad28287 (
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#!/bin/sh
#{{{ printhelp
printhelp () {
printf "bm: browser menu script; interface for browsers.\n"
printf " -b) basilisk interface\n"
printf " -B) brave browser\n"
printf " -d) firedragon interface\n"
printf " -f) firefox interface\n"
printf " -l) librewolf interface\n"
printf " -m) mullvad-browser interface\n"
printf " -q) qutebrowser interface\n"
printf " -d ARG) provide menu args\n"
printf " -u ARG) provide URL to open\n"
exit
}
#}}}
#{{{ BROWSERSBYCMD
# Native binaries
type basilisk >/dev/null 2>&1 && CANBSC="bsc"
type brave >/dev/null 2>&1 && CANBRA="brave"
type firedragon >/dev/null 2>&1 && CANFDC="fdc"
type firefox >/dev/null 2>&1 && CANFFC="ffc"
type librewolf >/dev/null 2>&1 && CANLWC="lwc"
type mullvad-browser >/dev/null 2>&1 && CANMBC="mbc"
type qutebrowser >/dev/null 2>&1 && CANQBC="qbc"
[ -n "$WAYLAND_DISPLAY" ] && \
type wl-copy >/dev/null 2>&1 && CANCLIPB="clip"
[ -z "$WAYLAND_DISPLAY" -a -n "$DISPLAY" ] && \
type xclip >/dev/null 2>&1 && CANCLIPB="clip"
# Flatpaks
LIST="$(flatpak list)"
echo "$LIST" | grep -q "org.mozilla.firefox" && CANFFC="ffc"
echo "$LIST" | grep -q "com.brave.Browser" && CANBRA="brave"
echo "$LIST" | grep -q "io.gitlab.librewolf-community" && \
CANLWC="lwc"
echo "$LIST" | grep -q "org.qutebrowser.qutebrowser" && \
CANQBC="qbc"
#}}}
#{{{ getopts
unset ARG BSC BRA FDC FFC LWC MBC QBC CLIPB URL
while getopts "hbBcrflmqxwd:u:" o; do case "${o}" in
b) BSC="y" ;;
B) BRA="y" ;;
r) FDC="y" ;;
f) FFC="y" ;;
l) LWC="y" ;;
m) MBC="y" ;;
q) QBC="y" ;;
c) CLIPB="y" ;;
d) ARG="$ARG-d $OPTARG ";;
u) URL="$OPTARG " ;;
*) printhelp ;;
esac done
#}}}
#{{{ clip
clip () {
ARG="$@"
if [ -n "$WAYLAND_DISPLAY" -a -n "$CANCLIPB" ]; then
echo -n $URL | wl-copy ${ARG%u}
elif [ -n "$DISPLAY" -a -n "$CANCLIPB" ]; then
echo -n $URL | xclip -selection clipboard ${ARG%-u}
fi
}
#}}}
#{{{ bra
bra () {
if [ -n "$CANBRA" ]; then
if type brave >/dev/null 2>&2; then
brave $@
else
flatpak run com.brave.Browser $@
fi
fi
}
#}}}
#{{{ Check display server if -w or -x not provided
if [ -n "$WAYLAND_DISPLAY" ]; then
DMENU="tofi"
DEFARGS="-c $HOME/.config/tofi/themes/dmenu_vertical --prompt-text"
elif [ -n "$DISPLAY" ]; then
DMENU="dmenu"
DEFARGS=" -l 10 -p"
else
print "Can't tell if Wayland or X; what gives?\n"
exit 1
fi
#}}}
#{{{ main
if [ -n "$BSC$FDC$FFC$LWC$QBC" ]; then
ARG="$ARG -u $URL"
fi
echo $ARG
[ -n "$BRA" ] && bra $ARG
[ -n "$BSC" ] && exec bsc $ARG
[ -n "$FDC" ] && exec fdc $ARG
[ -n "$FFC" ] && exec ffc $ARG
[ -n "$LWC" ] && exec lwc $ARG
[ -n "$MBC" ] && exec mbc $ARG
[ -n "$QBC" ] && exec qbc $ARG
[ -n "$CLIPB" ] && exec clip $ARG
if [ -z "$CLIPB$BRA$BSC$FDC$FFC$LWC$MBC$QBC" ]; then
BROWSERSINSTALLED=""
for i in CLIPB BRA BSC FDC FFC LWC QBC MBC; do
if [ -n "$(eval "echo \$CAN${i}")" ]; then
[ -n "$BROWSERSINSTALLED" ] && STARTLINE="\n" || STARTLINE="" ;
[ -z "$URL" -a "$i" = "CLIPB" ] && continue
BROWSERSINSTALLED="${BROWSERSINSTALLED}${STARTLINE}$(eval "echo \$CAN${i}")"
fi
done
echo "$BROWSERSINSTALLED"
[ -z "$BROWSERSINSTALLED" ] && \
printf "No suitable browsers!\n" && exit 1
BROWSERSEL="$(printf "$BROWSERSINSTALLED" | $DMENU $DEFARGS "browser?" $ARG)"
[ -z "$BROWSERSEL" ] && \
printf "No browser selected!\n" && exit 1
case "$BROWSERSEL" in
clip)
$BROWSERSEL $ARG
;;
brave)
bra $URL
;;
*)
$BROWSERSEL $ARG -u $URL
;;
esac
fi
#}}}
|