From 197d12b3fd1480d4ea24a81a2d56f15a7ef5bd43 Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 29 Aug 2025 18:43:07 +0200 Subject: [PATCH 1/2] feat(qutedmenu): delete items, rofi example and refactoring if the menu exits with status code 10 _(in bmenu it is alt+1 and rofi alt+d)_ the menu item gets deleted --- misc/userscripts/qutedmenu | 57 +++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/misc/userscripts/qutedmenu b/misc/userscripts/qutedmenu index 6e88d56d1..e3a8da435 100755 --- a/misc/userscripts/qutedmenu +++ b/misc/userscripts/qutedmenu @@ -3,6 +3,8 @@ #:bind o spawn --userscript /path/to/userscripts/qutedmenu open #:bind O spawn --userscript /path/to/userscripts/qutedmenu tab +#:bind wo spawn --userscript /path/to/userscripts/qutedmenu window +#:bind po spawn --userscript /path/to/userscripts/qutedmenu private # If you would like to set a custom colorscheme/font use these dirs. # https://github.com/halfwit/dotfiles/blob/master/.config/dmenu/bemenucolors @@ -12,6 +14,13 @@ readonly confdir=${XDG_CONFIG_HOME:-$HOME/.config} readonly optsfile=$confdir/dmenu/bemenucolors create_menu() { + opts+=(-p qutebrowser -l 10) + dmenu "${opts[@]}" + # bemenu "${opts[@]}" + # rofi -dmenu -kb-custom-1 "d" "${opts[@]}" +} + +create_menu_items() { # Check quickmarks while read -r url; do printf -- '%s\n' "$url" @@ -23,33 +32,31 @@ create_menu() { done < "$QUTE_CONFIG_DIR"/bookmarks/urls # Finally history - printf -- '%s\n' "$(sqlite3 -separator ' ' "$QUTE_DATA_DIR/history.sqlite" 'select title, url from CompletionHistory ORDER BY last_atime DESC')" - } - -get_selection() { - opts+=(-p qutebrowser) - create_menu | dmenu -l 10 "${opts[@]}" - #create_menu | bemenu -l 10 "${opts[@]}" + printf -- '%s\n' "$(sqlite3 -separator ' ' "$QUTE_DATA_DIR/history.sqlite" \ + 'select title, url from CompletionHistory ORDER BY last_atime DESC')" } -# Main -# https://github.com/halfwit/dotfiles/blob/master/.config/dmenu/font -[[ -s $confdir/dmenu/font ]] && read -r font < "$confdir"/dmenu/font +while true; do + selection=$(create_menu_items | create_menu) + exit_code=$? + url=${selection/*http/http} -[[ -n $font ]] && opts+=(-fn "$font") + # If no selection is made, exit (escape pressed, e.g.) + [[ -z $url ]] && exit 0 -# shellcheck source=/dev/null -[[ -s $optsfile ]] && source "$optsfile" + # Remove the corresponding history item if the menu exits with code 10 + if [[ $exit_code -eq 10 ]]; then + sqlite3 "$QUTE_DATA_DIR/history.sqlite" \ + "DELETE FROM CompletionHistory WHERE url='$url';" + continue + fi -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 + # Normal selection → open and exit + 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 + exit 0 +done From f8d9545764d87b26b6c33b96d9de0c9022541e46 Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 29 Aug 2025 18:48:47 +0200 Subject: [PATCH 2/2] chore: revert deleted code --- misc/userscripts/qutedmenu | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/misc/userscripts/qutedmenu b/misc/userscripts/qutedmenu index e3a8da435..6236024a4 100755 --- a/misc/userscripts/qutedmenu +++ b/misc/userscripts/qutedmenu @@ -36,6 +36,15 @@ create_menu_items() { 'select title, url from CompletionHistory ORDER BY last_atime DESC')" } +# 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" + while true; do selection=$(create_menu_items | create_menu) exit_code=$?