aboutsummaryrefslogtreecommitdiff
path: root/scripts/bbpick
blob: ec66653261f2dc6f6c0ad00ada892289877a9211 (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
#!/bin/sh
# Pick from the provided input
if [ -z "$PICKER" ]; then
    if command -v fzf >/dev/null; then
        PICKER=fzf
    elif command -v fzy >/dev/null; then
        PICKER=fzy
    elif command -v ask >/dev/null; then
        PICKER=ask
    elif command -v dmenu >/dev/null; then
        PICKER=dmenu
    elif command -v pick >/dev/null; then
        PICKER=pick
    fi
fi

case "$PICKER" in
    fzf*)
        printf '\033[3A\033[?25h' >/dev/tty
        fzf --read0 --height=6 --prompt="$(printf "$1")"
        ;;
    fzy*)
        printf '\033[3A\033[?25h' >/dev/tty
        tr '\0' '\n' | fzy --lines=5 --prompt="$(printf "\033[1m$1\033[0m")"
        ;;
    ask*)
        ask --read0 --prompt="$(printf "$1\033[?25h")"
        ;;
    dmenu*)
        tr '\0' '\n' | dmenu -i -l 10 -p "$(printf "$1")"
        ;;
    pick*)
		printf '\033[?25h' >/dev/tty
        tr '\0' '\n' | pick
        ;;
    *)
        query="$(bbask "$1")" && grep -i -m1 "$(echo "$query" | sed 's;.;[^/&]*[&];g')"
        ;;
esac