dotfiles/.bin/dexec_browser

211 lines
7.3 KiB
Plaintext
Raw Normal View History

2022-12-06 08:01:44 +01:00
#!/bin/sh
# 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)
HISTFILE="${HOME}/.browser_history"
test -f ${HOME}/.bin/_config \
&& . ${HOME}/.bin/_config \
|| DMENU_CMD=dmenu
test -f "${HISTFILE}" \
|| touch "${HISTFILE}"
2023-01-31 18:41:01 +01:00
HISTDATA="$(while IFS= read -r l; do echo "${#l} $((++n)) $l"; done \
< "${HISTFILE}" \
| sed 's|/$||;s|http[s]\{0,1\}://||' \
| sort -t\| -k 2 -u \
| sort -n \
| cut -d" " -f3-)"
2023-01-30 10:56:19 +01:00
2022-12-06 08:01:44 +01:00
PICKLIST="paste_from_clipboard
pick_from_history
2023-01-07 15:07:46 +01:00
edit_history_file
2022-12-06 08:01:44 +01:00
-----------------
2023-01-30 10:56:19 +01:00
$(echo "${HISTDATA}" \
2022-12-06 08:01:44 +01:00
| cut -b 23- \
| egrep -v ' |^[^a-zA-Z0-9]' \
2023-01-07 15:07:46 +01:00
| grep '..\...'\
2023-01-01 10:16:54 +01:00
)
2022-12-06 08:01:44 +01:00
http://localhost"
# show filtered history file
# EXPECTS: $PICKLIST $HISTFILE $DMENU_CMD
# PROVIDES: $INPUT
read_input() {
local S=$(printf '%s\n' "${PICKLIST}" \
| ${DMENU_CMD} -p "Bookmarks")
case "${S}" in
paste_from_clipboard)
S=$(xclip -o \
| head -n 1) ;;
pick_from_history)
S=$(sort -r "${HISTFILE}" \
| ${DMENU_CMD} -p "History:" \
|cut -b23-) ;;
2023-01-07 15:07:46 +01:00
edit_history_file)
texec "vim +\$ ${HISTFILE}"
dexec_browser
exit 0 ;;
2022-12-06 08:01:44 +01:00
esac
[ -z "${S}" ] && exit 0
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
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)"; ;;
192.168.*) DEFAULT="OPEN (default)"; ;;
gopher*) DEFAULT="OPEN (default)"; ;;
2022-12-11 11:55:10 +01:00
g_*) DEFAULT="GLIB Documentation"; ;;
[Ss]oup_*) DEFAULT="LibSOUP Documentation"; ;;
2022-12-06 08:01:44 +01:00
www.*) DEFAULT="OPEN (default)"; ;;
\<*@*\>) DEFAULT="Marc Info Message ID (default)"; ;;
*.com|*.de|*.net|*.org) DEFAULT="OPEN (default)"; ;;
*.at|*.ch|*.social) DEFAULT="OPEN (default)"; ;;
*.io|*.sh|*.pw|*.party) DEFAULT="OPEN (default)"; ;;
*.coffee|*.me|*.cloud) DEFAULT="OPEN (default)"; ;;
*.[a-zA-Z]*/*) DEFAULT="OPEN (default)"; ;;
*) DEFAULT="DuckDuckGo Web Search (default)"; ;;
esac
local S="$(printf "%s\n%s" "${DEFAULT}" "${SE}" \
| ${DMENU_CMD} -p "Search Where?")"
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}"; ;;
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() {
case "${URI}" in
gopher://*) DEFAULT="Lagrange (default)"; ;;
gemini://*) DEFAULT="Lagrange (default)"; ;;
*.pdf|*.cb|*.ps) DEFAULT="Zathura (default)"; ;;
2023-03-28 18:19:41 +02:00
192.168.*) DEFAULT="Chrome (default)"; ;;
*github.com*) DEFAULT="Chrome (default)"; ;;
*amazon.de*) DEFAULT="Chrome (default)"; ;;
*twitter.com*) DEFAULT="Chrome (default)"; ;;
*chaos.social*) DEFAULT="Chrome (default)"; ;;
*hetzner.cloud*) DEFAULT="Chrome (default)"; ;;
*hetzner.de*) DEFAULT="Chrome (default)"; ;;
*duckduckgo.com/*images*) DEFAULT="Chrome (default)"; ;;
2022-12-06 08:01:44 +01:00
*codevoid.de*) DEFAULT="Luakit (default)"; ;;
2023-03-28 18:19:41 +02:00
*google.*) DEFAULT="Chrome (default)"; ;;
*youtube.com*) DEFAULT="Chrome (default)"; ;;
*youtu.be*) DEFAULT="Chrome (default)"; ;;
*bsd.network*) DEFAULT="Chrome (default)"; ;;
*itch.io*) DEFAULT="Chrome (default)"; ;;
*chat.uugrn.org*) DEFAULT="Chrome (default)"; ;;
*[./]amazon.*) DEFAULT="Chrome (default)"; ;;
*comdirect.de*) DEFAULT="Chrome (default)"; ;;
*motorradfreunde-rheinneckar.de*) DEFAULT="Chrome (default)"; ;;
*polo-motorrad.com*) DEFAULT="Chrome (default)"; ;;
*peek-cloppenburg.de*) DEFAULT="Chrome (default)"; ;;
*asos.com*) DEFAULT="Chrome (default)"; ;;
*zalando.de*) DEFAULT="Chrome (default)"; ;;
2023-03-15 17:47:09 +01:00
*) DEFAULT="Chrome (default)"; ;;
2022-12-06 08:01:44 +01:00
esac
local S="${DEFAULT}\nLuakit\nFirefox\nChrome\nQutebrowser\nNetsurf\nTor-Browser"
case $(echo "${S}" | ${DMENU_CMD} -p "Browser") in
Netsurf*) BROWSER=netsurf-gtk3 ;;
Vimb*) BROWSER=vimb ;;
Quteb*r*) BROWSER=qutebrowser ;;
Surf*) BROWSER=surf ;;
Otter*r*) BROWSER=otter-browser ;;
Luakit*) BROWSER="luakit -Un" ;;
Chrome*) BROWSER=chrome ;;
Firefox*) BROWSER=firefox ;;
Tor-B*r*) BROWSER=tor-browser ;;
Zathura*) BROWSER=zathura ;;
Lagrange*) BROWSER=lagrange ;;
*) exit 0;;
esac
}
save_history() {
printf '%s %s\n' "$(date +"%Y-%m-%d %H:%M:%S |")" "${INPUT}" \
>> "${HISTFILE}"
}
# main program starts here.
read_input
choose_wrapper
choose_browser
save_history
exec $BROWSER "$(printf '%s' "${URI}" | sed 's/ /%20/g')"