summaryrefslogtreecommitdiff
path: root/misc/userscripts/qutedmenu
blob: bdd0d9b2704c83753bfb893e74e65d4bc1aca956 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/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 | 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"  ;;
esac