72 lines
2.3 KiB
Bash
Executable File
72 lines
2.3 KiB
Bash
Executable File
#!/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
|
|
#: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
|
|
|
|
|
|
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"
|
|
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 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=$?
|
|
url=${selection/*http/http}
|
|
|
|
# If no selection is made, exit (escape pressed, e.g.)
|
|
[[ -z $url ]] && exit 0
|
|
|
|
# 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
|
|
|
|
# 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
|