dotfiles/qutebrowser/scripts/qutedmenu
Marty Oehme 59677f3b9c
qutebrowser: Include sessions into qutedmenu script
If 'yq' is found on the system, the qutedmenu script will now also
traverse any saved sessions for urls (either active or historic) and
display those as well.

Also added a simple check for the sqlite3 and yq tools and spit out a
warning if either isn't found. Program will continue unhindered and just
ignore the history/session urls respectively.
2025-01-03 22:32:55 +01:00

79 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Open any of: quickmarks, bookmarks and browser history via dmenu (or rofi)
# Handle open -s && open -t with bemenu
#
# Requires sqlite3 binary installed to traverse the history.
#:bind o spawn --userscript /path/to/userscripts/qutedmenu open
#:bind O spawn --userscript /path/to/userscripts/qutedmenu tab
warn() {
echo "$1" >&2
}
readonly confdir=${XDG_CONFIG_HOME:-$HOME/.config}
readonly datadir=${XDG_DATA_HOME:-$HOME/.local/share}
readonly optsfile=$confdir/dmenu/bemenucolors
readonly QUTE_CONFIG_DIR="${QUTE_CONFIG_DIR:-$confdir/qutebrowser}"
readonly QUTE_DATA_DIR="${QUTE_DATA_DIR:-$datadir/qutebrowser}"
create_menu() {
# Check quickmarks
while read -r url; do
printf -- '%s\n' "$url"
done <"$QUTE_CONFIG_DIR"/quickmarks
# Next bookmarks
while read -r url _; do
printf -- '%s\n' "$url"
done <"$QUTE_CONFIG_DIR"/bookmarks/urls
# Saved sessions
if type yq >/dev/null 2>&1; then
while read -r url; do
printf -- '%s\n' "$url"
done < <(yq ".windows.[].tabs.[].history.[].url" "${QUTE_DATA_DIR}"/sessions/*.yml | sed -e 's/^"\(.*\)"$/\1/')
else
warn "Did not find yq executable, not searching saved sessions."
fi
# Finally history
if type sqlite3 >/dev/null 2>&1; then
printf -- '%s\n' "$(sqlite3 -separator ' ' "$QUTE_DATA_DIR/history.sqlite" 'select title, url from CompletionHistory')"
else
warn "Did not find sqlite3 executable, not searching history."
fi
}
get_selection() {
opts+=(-p qutebrowser)
local launcher
if exist bemenu; then
launcher=bemenu
elif exist dmenu; then
launcher=dmenu
fi
create_menu | "$launcher" -l 10 "${opts[@]}"
}
# Main
# https://github.com/halfwit/dotfiles/blob/master/.config/dmenu/font
[[ -s $confdir/dmenu/font ]] && read -r font <"$confdir"/dmenu/font
[[ -n $font ]] && opts+=(-fn "$font")
# shellcheck source=/dev/null
[[ -s $optsfile ]] && source "$optsfile"
url=$(get_selection)
url=${url/*http/http}
# If no selection is made, exit (escape pressed, e.g.)
[[ -z $url ]] && exit 0
case $1 in
open) printf '%s' "open $url" >>"$QUTE_FIFO" || qutebrowser "$url" ;;
print) echo "$url" ;;
tab | *) printf '%s' "open -t $url" >>"$QUTE_FIFO" || qutebrowser "$url" ;;
esac