2023-10-24 16:14:42 +02:00
|
|
|
#!/bin/ksh
|
2022-12-06 08:01:44 +01:00
|
|
|
|
|
|
|
# dexec_browser
|
|
|
|
# A multi browser launcher
|
|
|
|
#
|
|
|
|
# 1. choose input source
|
|
|
|
# (filtered-, full history, clipboad, manual entry)
|
|
|
|
# 2. choose how to handle the input
|
|
|
|
# (can suggest a matching default)
|
|
|
|
# 3. choose which browser to use
|
|
|
|
# (can suggest a matching default)
|
|
|
|
|
2023-10-12 08:18:44 +02:00
|
|
|
. ${HOME}/.bin/_config
|
2022-12-06 08:01:44 +01:00
|
|
|
|
2023-10-12 08:18:44 +02:00
|
|
|
HISTFILE="${HOME}/.browser_history"
|
|
|
|
touch "${HISTFILE}"
|
2022-12-06 08:01:44 +01:00
|
|
|
|
2023-10-12 08:18:44 +02:00
|
|
|
# show history file
|
|
|
|
# EXPECTS: $HISTFILE $DMENU_CMD
|
2022-12-06 08:01:44 +01:00
|
|
|
# PROVIDES: $INPUT
|
|
|
|
read_input() {
|
2023-10-12 08:18:44 +02:00
|
|
|
local S=$( { echo "paste_from_clipboard"; tail -r ${HISTFILE}; } \
|
|
|
|
| awk '!seen[$0]++' \
|
2024-01-17 18:18:42 +01:00
|
|
|
| ${DMENU_CMD} -p "Bookmarks" -l 20)
|
2023-10-12 08:18:44 +02:00
|
|
|
|
2022-12-06 08:01:44 +01:00
|
|
|
case "${S}" in
|
2023-10-12 08:18:44 +02:00
|
|
|
paste_from_clipboard) S=$(xclip -o | head -n 1); ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
esac
|
2023-10-12 08:18:44 +02:00
|
|
|
|
2022-12-06 08:01:44 +01:00
|
|
|
[ -z "${S}" ] && exit 0
|
2023-10-12 08:18:44 +02:00
|
|
|
|
2022-12-06 08:01:44 +01:00
|
|
|
INPUT="${S}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Decide how to open the thing
|
|
|
|
# EXPECTS: $INPUT $DMENU_CMD
|
|
|
|
# PROVIDES: $URI
|
|
|
|
choose_wrapper() {
|
|
|
|
|
|
|
|
local SE="OPEN URL
|
|
|
|
Amazon
|
|
|
|
CPAN
|
|
|
|
Crates.io
|
|
|
|
DuckDuckGo Web Search
|
|
|
|
DuckDuckGo Image Search
|
2024-01-01 23:15:04 +01:00
|
|
|
Startpage Web Search
|
2022-12-11 11:55:10 +01:00
|
|
|
GLIB Documentation
|
2022-12-06 08:01:44 +01:00
|
|
|
Github
|
2022-12-11 11:55:10 +01:00
|
|
|
LibSOUP Documentation
|
2022-12-06 08:01:44 +01:00
|
|
|
Marc Info MessageID
|
|
|
|
Marc Info OpenBSD Misc List
|
|
|
|
Marc Info OpenBSD Ports CVS
|
|
|
|
Marc Info OpenBSD Ports List
|
|
|
|
Marc Info OpenBSD Tech List
|
|
|
|
PDF Viewer
|
|
|
|
SearX Web Search
|
|
|
|
SearX Image Search
|
2023-03-06 08:14:38 +01:00
|
|
|
Torrent Leech
|
2022-12-06 08:01:44 +01:00
|
|
|
Wikipedia DE
|
|
|
|
Wikipedia EN
|
|
|
|
InternetMovieDataBase (IMDB)
|
|
|
|
OpenStreetMap (OSM)
|
|
|
|
Grep.app
|
|
|
|
Google Maps
|
2023-01-07 15:07:46 +01:00
|
|
|
Youtube
|
2023-02-22 08:18:57 +01:00
|
|
|
Zalando"
|
2022-12-06 08:01:44 +01:00
|
|
|
|
|
|
|
local C="$(printf '%s' "${INPUT}" \
|
|
|
|
| head -n 1)"
|
|
|
|
case "${C}" in
|
|
|
|
*::*) DEFAULT="CPAN (default)"; ;;
|
|
|
|
http*) DEFAULT="OPEN (default)"; ;;
|
2023-04-09 09:37:39 +02:00
|
|
|
192.168.*) DEFAULT="OPEN (default)"; C="http://${C}"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
gopher*) DEFAULT="OPEN (default)"; ;;
|
2022-12-11 11:55:10 +01:00
|
|
|
g_*) DEFAULT="GLIB Documentation"; ;;
|
|
|
|
[Ss]oup_*) DEFAULT="LibSOUP Documentation"; ;;
|
2023-04-09 09:37:39 +02:00
|
|
|
www.*) DEFAULT="OPEN (default)"; C="http://${C}"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
\<*@*\>) DEFAULT="Marc Info Message ID (default)"; ;;
|
2023-04-09 09:37:39 +02:00
|
|
|
*.com|*.de|*.net|*.org) DEFAULT="OPEN (default)"; C="http://${C}"; ;;
|
|
|
|
*.at|*.ch|*.social) DEFAULT="OPEN (default)"; C="http://${C}" ;;
|
|
|
|
*.io|*.sh|*.pw|*.party) DEFAULT="OPEN (default)"; C="http://${C}"; ;;
|
|
|
|
*.coffee|*.me|*.cloud) DEFAULT="OPEN (default)"; C="http://${C}"; ;;
|
|
|
|
*.[a-zA-Z]*/*) DEFAULT="OPEN (default)"; C="http://${C}"; ;;
|
2024-01-01 23:15:04 +01:00
|
|
|
*) DEFAULT="Startpage Web Search (default)"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
esac
|
|
|
|
|
|
|
|
local S="$(printf "%s\n%s" "${DEFAULT}" "${SE}" \
|
2024-01-17 18:18:42 +01:00
|
|
|
| ${DMENU_CMD} -p "Search Where?" -l 20)"
|
2023-03-06 08:14:38 +01:00
|
|
|
C=$(echo "$C" | sed 's/ /%20/g')
|
2022-12-06 08:01:44 +01:00
|
|
|
case "${S}" in
|
|
|
|
OPEN*) URI="${C}"; ;;
|
|
|
|
Amazon*) URI="https://www.amazon.de/s?k=${C}"; ;;
|
|
|
|
CPAN*) URI="https://metacpan.org/search?q=${C}"; ;;
|
|
|
|
Crate*) URI="https://crates.io/search?q=${C}"; ;;
|
|
|
|
Grep*) URI="https://grep.app/search?q=${C}"; ;;
|
2022-12-11 11:55:10 +01:00
|
|
|
GLIB*) URI="https://docs.gtk.org/glib/flags.UriFlags.html?q=${C}"; ;;
|
|
|
|
LibSOUP*) URI="https://libsoup.org/libsoup-3.0/index.html?q=${C}"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
Github) URI="https://github.com/search?q=${C}"; ;;
|
|
|
|
D*Web*) URI="https://html.duckduckgo.com/html?q=${C}"; ;;
|
2024-01-01 23:15:04 +01:00
|
|
|
Startpage*) URI="https://eu.startpage.com/do/search?prfe=00d4bb7f075582be9304aaad813ac6b4dc4bd733a098955c35c0586a99eaddf123ac81f1301f1e4f06fd014082141134ec5e0c5441250cf4c05557bed28fcfbced8de0007d01a0254332962533&query=${C}"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
D*Ima*) URI="https://duckduckgo.com/?q=${C}&iax=images&ia=images"; ;;
|
|
|
|
S*Web*) URI="https://searx.bar/search?q=${C}&category_general=on"; ;;
|
|
|
|
S*Ima*) URI="https://searx.bar/search?q=${C}&category_images=on"; ;;
|
2023-03-06 08:14:38 +01:00
|
|
|
Tor*Lee*) URI="https://www.torrentleech.org/torrents/browse/index/query/${C}"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
W*DE*) URI="https://de.m.wikipedia.org/wiki/Spezial:Suche/${C}"; ;;
|
|
|
|
W*EN*) URI="https://en.m.wikipedia.org/wiki/Spezial:Search/${C}"; ;;
|
|
|
|
*IMDB*) URI="https://www.imdb.com/find?q=${C}"; ;;
|
|
|
|
O*S*M*) URI="https://www.openstreetmap.org/search?query=${C}"; ;;
|
|
|
|
G*Maps) URI="https://www.google.com/maps/place/${C}"; ;;
|
|
|
|
You*be) URI="https://m.youtube.com/results?sp=mAEA&search_query=${C}" ;;
|
|
|
|
M*I*ID*) URI="https://marc.info/?i=$(printf '%s' "${C}" | tr -d '<>')"; ;;
|
|
|
|
M*I*P*List) URI="https://marc.info/?l=openbsd-ports&s=${C}&q=b"; ;;
|
|
|
|
M*I*T*List) URI="https://marc.info/?l=openbsd-tech&s=${C}&q=b"; ;;
|
|
|
|
M*I*M*List) URI="https://marc.info/?l=openbsd-misc&s=${C}&q=b"; ;;
|
|
|
|
M*I*P*CVS) URI="https://marc.info/?l=openbsd-ports-cvs&s=${C}&q=b"; ;;
|
2023-02-22 08:18:57 +01:00
|
|
|
Zalando) URI="https://www.zalando.de/herren/?q=${C}"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
*) exit 0 ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# Which browser shall we use?
|
|
|
|
# EXPECTS: $URI $DMENU_CMD
|
|
|
|
# PROVIDES: $BROWSER
|
|
|
|
choose_browser() {
|
2023-12-28 22:52:07 +01:00
|
|
|
|
2022-12-06 08:01:44 +01:00
|
|
|
case "${URI}" in
|
2023-12-30 08:31:01 +01:00
|
|
|
gopher://*) DEFAULT="Lagrange (default)"; ;;
|
|
|
|
gemini://*) DEFAULT="Lagrange (default)"; ;;
|
2024-01-08 23:06:28 +01:00
|
|
|
*console.hetzner.cloud*) DEFAULT="Firefox (default)"; ;;
|
2023-11-05 12:22:05 +01:00
|
|
|
*youtube.com/watch*) DEFAULT="Mpv (default)"; ;;
|
2023-12-30 08:31:01 +01:00
|
|
|
*media.ccc.de/v/*) DEFAULT="Mpv (default)"; ;;
|
|
|
|
*.pdf|*.cb|*.ps) DEFAULT="Zathura (default)"; ;;
|
|
|
|
*.mp4|*.m4v|*.mkv) DEFAULT="Mpv (default)"; ;;
|
|
|
|
*) DEFAULT="$BROWSER (default)"; ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
esac
|
|
|
|
|
2023-11-19 08:40:50 +01:00
|
|
|
local S="${DEFAULT}\nLuakit\nVimb\nFirefox\nChrome\nQutebrowser\nWyeb\nNetsurf\nTor-Browser\nDillo\nSurf\nMpv"
|
2022-12-06 08:01:44 +01:00
|
|
|
case $(echo "${S}" | ${DMENU_CMD} -p "Browser") in
|
2023-10-24 16:14:42 +02:00
|
|
|
[Nn]etsurf*) BROWSER=netsurf-gtk3 ;;
|
2023-12-28 22:52:07 +01:00
|
|
|
[Vv]imb*) BROWSER="vimb --no-maximize" ;;
|
2023-11-02 08:16:26 +01:00
|
|
|
[Dd]illo*) BROWSER=dillo; ;;
|
2023-12-28 22:52:07 +01:00
|
|
|
[Qq]uteb*r*) BROWSER="qutebrowser -R" ;;
|
2023-10-24 16:14:42 +02:00
|
|
|
[Ss]urf*) BROWSER=surf ;;
|
|
|
|
[Oo]tter*r*) BROWSER=otter-browser ;;
|
|
|
|
[Ll]uakit*) BROWSER="luakit -Un" ;;
|
|
|
|
[Cc]hrome*) BROWSER=chrome ;;
|
|
|
|
[Ff]irefox*) BROWSER=firefox ;;
|
|
|
|
[Tt]or-B*r*) BROWSER=tor-browser ;;
|
|
|
|
[Zz]athura*) BROWSER=zathura ;;
|
|
|
|
[Ll]agrange*) BROWSER=lagrange ;;
|
2023-11-19 08:40:50 +01:00
|
|
|
[Ww]yeb*) BROWSER=wyeb ;;
|
2023-12-30 08:31:01 +01:00
|
|
|
[Mm]pv*) BROWSER="mpv" ;;
|
2022-12-06 08:01:44 +01:00
|
|
|
*) exit 0;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
save_history() {
|
2023-10-12 08:18:44 +02:00
|
|
|
printf '%s\n' "${INPUT}" | sed 's/^ *//g;s/ *$//g' >> "${HISTFILE}"
|
2022-12-06 08:01:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# main program starts here.
|
|
|
|
read_input
|
|
|
|
choose_wrapper
|
2024-01-17 18:18:42 +01:00
|
|
|
# choose_browser
|
2022-12-06 08:01:44 +01:00
|
|
|
save_history
|
|
|
|
exec $BROWSER "$(printf '%s' "${URI}" | sed 's/ /%20/g')"
|