From f22ccae6fd60988a96cee3766bb168eccd8ebe41 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 11 Nov 2015 23:21:33 -0700 Subject: [PATCH] Create qutedmenu Bemenu integration for Qutebrowser --- misc/userscripts/qutedmenu | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 misc/userscripts/qutedmenu diff --git a/misc/userscripts/qutedmenu b/misc/userscripts/qutedmenu new file mode 100644 index 000000000..e4a97f589 --- /dev/null +++ b/misc/userscripts/qutedmenu @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# Handle open -s && open -t with bemenu + +# Broken out to two files to handle flag passing +#:bind o spawn --userscript /path/to/userscripts/openpage +#:bind O spawn --userscript /path/to/userscripts/qutedmenu + +# If you would like to set a custom colorscheme/font use these dirs. +# https://github.com/halfwit/dotfiles/blob/master/.config/dmenu/bemenucolors +readonly confdir=${XDG_CONFIG_HOME:-$HOME/.config} +readonly datadir=${XDG_DATA_HOME:-$HOME/.local/share} + +readonly optsfile=$confdir/dmenu/bemenucolors + +create_menu() { + # Check quickmarks + while read -r url; do + printf -- '%s\n' "$url" + done < "$confdir"/qutebrowser/quickmarks + + # Next bookmarks + while read -r url _; do + printf -- '%s\n' "$url" + done < "$confdir"/qutebrowser/bookmarks/urls + + # Finally history + while read -r _ url; do + printf -- '%s\n' "$url" + done < "$datadir"/qutebrowser/history + } + +get_selection() { + opts+=(-p Qutebrowser) + #create_menu | dmenu -l 10 "${opts[@]}" + create_menu | bemenu -l 10 "${opts[@]}" +} + +# Main +# https://github.com/halfwit/dotfiles/blob/master/.config/dmenu/font +if [[ -s $confdir/dmenu/font ]]; then + read -r font < "$confdir"/dmenu/font +fi + +if [[ $font ]]; then + opts+=(-fn "$font") +fi + +if [[ -s $optsfile ]]; then + source "$optsfile" +fi + +url=$(get_selection) +url=${url/*http/http} + +# If no selection is made, exit (escape pressed, e.g.) +[[ ! $url ]] && exit 0 + +case $1 in + open) printf '%s' "open $url" >> "$QUTE_FIFO" || qutebrowser "$url" ;; + *) printf '%s' "open -t $url" >> "$QUTE_FIFO" || qutebrowser "$url" ;; +esac