From f94759697d4cf267577ddc0fc3f144290fa33686 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 18 Aug 2021 23:26:36 +0200 Subject: [PATCH] qutebrowser: Add launcher to open links Added bemenu launcher (can alternatively use dmenu) to find and quickly open a link in the current qutebrowser instance (or a new one if none exist). Will open it by default in a new tab or if `tab` argument passed, if `open` option is passed it will open it in the current page instead. The script can be used both standalone by being invoked as `qutedmenu`, or from qutebrowser itself, invoked from its commandline as `spawn --userscript qutedmenu `. By default uses bemenu, but if that is not found on system will automatically switch to make use of dmenu. If you want to use rofi as your dmenu replacement, generally I will assume it is already symlinked to dmenu. Added a keymapping to sxhkd `Mod-Shift-O`, which invokes it from anywhere. --- qutebrowser/.local/bin/qutedmenu | 58 +++++++++++++++++++ .../share/qutebrowser/userscripts/qutedmenu | 1 + sxhkd/.config/sxhkd/sxhkdrc | 4 ++ 3 files changed, 63 insertions(+) create mode 100755 qutebrowser/.local/bin/qutedmenu create mode 120000 qutebrowser/.local/share/qutebrowser/userscripts/qutedmenu diff --git a/qutebrowser/.local/bin/qutedmenu b/qutebrowser/.local/bin/qutedmenu new file mode 100755 index 0000000..39e3c8a --- /dev/null +++ b/qutebrowser/.local/bin/qutedmenu @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# Open any of: quickmarks, bookmarks and browser history via dmenu (or rofi) +# Handle open -s && open -t with bemenu + +#:bind o spawn --userscript /path/to/userscripts/qutedmenu open +#:bind O spawn --userscript /path/to/userscripts/qutedmenu tab + +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 + + # Finally history + printf -- '%s\n' "$(sqlite3 -separator ' ' "$QUTE_DATA_DIR/history.sqlite" 'select title, url from CompletionHistory')" +} + +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" ;; +tab | *) printf '%s' "open -t $url" >>"$QUTE_FIFO" || qutebrowser "$url" ;; +esac diff --git a/qutebrowser/.local/share/qutebrowser/userscripts/qutedmenu b/qutebrowser/.local/share/qutebrowser/userscripts/qutedmenu new file mode 120000 index 0000000..388267f --- /dev/null +++ b/qutebrowser/.local/share/qutebrowser/userscripts/qutedmenu @@ -0,0 +1 @@ +../../../bin/qutedmenu \ No newline at end of file diff --git a/sxhkd/.config/sxhkd/sxhkdrc b/sxhkd/.config/sxhkd/sxhkdrc index b011193..3a0ebe5 100644 --- a/sxhkd/.config/sxhkd/sxhkdrc +++ b/sxhkd/.config/sxhkd/sxhkdrc @@ -59,6 +59,10 @@ super + shift + e super + shift + u alacritty --class floating,floating -e sharefile | xargs notify-send +# invoke qutebrowser userscript to open link (from history/marks) +super + shift + o + qutedmenu + ## modes # mode:media:alt + m