From 751f51dab083dd597b660aed821453171fe90970 Mon Sep 17 00:00:00 2001 From: Andre Ramnitz Date: Mon, 15 Jan 2024 08:42:23 +0100 Subject: [PATCH] qutebrowser: remove symlink and move userscripts to local --- config/qutebrowser/config.py | 3 + .../qutebrowser/userscripts/dmenu_qutebrowser | 36 ++++++++++++ .../share}/qutebrowser/userscripts/qr | 0 .../qutebrowser/userscripts/qute-keepassxc | 0 local/share/qutebrowser/userscripts/qutedmenu | 56 +++++++++++++++++++ .../qutebrowser/userscripts/view_in_mpv | 0 6 files changed, 95 insertions(+) create mode 100755 local/share/qutebrowser/userscripts/dmenu_qutebrowser rename {config => local/share}/qutebrowser/userscripts/qr (100%) rename {config => local/share}/qutebrowser/userscripts/qute-keepassxc (100%) create mode 100755 local/share/qutebrowser/userscripts/qutedmenu rename {config => local/share}/qutebrowser/userscripts/view_in_mpv (100%) diff --git a/config/qutebrowser/config.py b/config/qutebrowser/config.py index 19a42a87..d37575c6 100644 --- a/config/qutebrowser/config.py +++ b/config/qutebrowser/config.py @@ -1232,6 +1232,9 @@ c.fonts.web.size.minimum_logical = 7 # Bindings for normal mode config.unbind('+') +config.unbind('q') +config.bind('q', 'spawn --userscript dmenu_qutebrowser') +config.bind('Q', 'spawn --userscript qr') config.bind('j', 'cmd-run-with-count 3 scroll down') config.bind('k', 'cmd-run-with-count 3 scroll up') config.bind(',M', 'hint links spawn vlc {hint-url}') diff --git a/local/share/qutebrowser/userscripts/dmenu_qutebrowser b/local/share/qutebrowser/userscripts/dmenu_qutebrowser new file mode 100755 index 00000000..addf63b3 --- /dev/null +++ b/local/share/qutebrowser/userscripts/dmenu_qutebrowser @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# SPDX-FileCopyrightText: Zach-Button +# SPDX-FileCopyrightText: Florian Bruhin (The Compiler) +# +# SPDX-License-Identifier: GPL-3.0-or-later + +# Pipes history, quickmarks, and URL into dmenu. +# +# If run from qutebrowser as a userscript, it runs :open on the URL +# If not, it opens a new qutebrowser window at the URL +# +# Ideal for use with tabs_are_windows. Set a hotkey to launch this script, then: +# :bind o spawn --userscript dmenu_qutebrowser +# +# Use the hotkey to open in new tab/window, press 'o' to open URL in current tab/window +# You can simulate "go" by pressing "o", as the current URL is always first in the list +# +# I personally use "o" to launch this script. For me, my workflow is: +# Default keys Keys with this script +# O o +# o o +# go o +# gO gC, then o +# (This is unnecessarily long. I use this rarely, feel free to make this script accept parameters.) +# + + +[ -z "$QUTE_URL" ] && QUTE_URL='https://duckduckgo.com' + +url=$(printf "%s\n%s" "$QUTE_URL" "$(sqlite3 -separator ' ' "$QUTE_DATA_DIR/history.sqlite" 'select title, url from CompletionHistory')" | cat "$QUTE_CONFIG_DIR/quickmarks" - | fuzzel -d -l 15 -w 150 -p qutebrowser) +url=$(echo "$url" | sed -E 's/[^ ]+ +//g' | grep -E "https?:" || echo "$url") + +[ -z "${url// }" ] && exit + +echo "open $url" >> "$QUTE_FIFO" || qutebrowser "$url" diff --git a/config/qutebrowser/userscripts/qr b/local/share/qutebrowser/userscripts/qr similarity index 100% rename from config/qutebrowser/userscripts/qr rename to local/share/qutebrowser/userscripts/qr diff --git a/config/qutebrowser/userscripts/qute-keepassxc b/local/share/qutebrowser/userscripts/qute-keepassxc similarity index 100% rename from config/qutebrowser/userscripts/qute-keepassxc rename to local/share/qutebrowser/userscripts/qute-keepassxc diff --git a/local/share/qutebrowser/userscripts/qutedmenu b/local/share/qutebrowser/userscripts/qutedmenu new file mode 100755 index 00000000..e2ca47a3 --- /dev/null +++ b/local/share/qutebrowser/userscripts/qutedmenu @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# 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 + +# 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 optsfile=$confdir/dmenu/bemenucolors + +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) + create_menu | fuzzel -d -l 10 "${opts[@]}" + #create_menu | dmenu -l 10 "${opts[@]}" + #create_menu | bemenu -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" ;; + window) printf '%s' "open -w $url" >> "$QUTE_FIFO" || qutebrowser "$url --target window" ;; + private) printf '%s' "open -p $url" >> "$QUTE_FIFO" || qutebrowser "$url --target private-window" ;; +esac diff --git a/config/qutebrowser/userscripts/view_in_mpv b/local/share/qutebrowser/userscripts/view_in_mpv similarity index 100% rename from config/qutebrowser/userscripts/view_in_mpv rename to local/share/qutebrowser/userscripts/view_in_mpv -- 2.51.2