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
This commit is contained in:
Sander 2025-08-29 18:43:07 +02:00 committed by GitHub
parent c0216a1309
commit 197d12b3fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 32 additions and 25 deletions

View File

@ -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 "<Alt>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