File: ddgr-completion.bash

package info (click to toggle)
ddgr 2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: python: 1,266; sh: 53; makefile: 6
file content (66 lines) | stat: -rw-r--r-- 1,445 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
#
# Rudimentary Bash completion definition for ddgr.
#
# Author:
#   Arun Prakash Jana <engineerarun@gmail.com>
#

_ddgr () {
    COMPREPLY=()
    local IFS=$' \n'
    local cur=$2 prev=$3
    local -a opts opts_with_args
    opts=(
        -h --help
        -n --num
        -r --reg
        -C --nocolor
        --colors
        -j --ducky
        -t --time
        -w --site
        -x --expand
        -p --proxy
        --unsafe
        --noua
        --json
        --gb --gui-browser
        --np --noprompt
        --rev --reverse
        --url-handler
        --show-browser-logs
        -v --version
        -d --debug
    )
    opts_with_arg=(
        -n --num
        -r --reg
        --colors
        -t --time
        -w --site
        -p --proxy
        --url-handler
    )

    if [[ $cur == -* ]]; then
        # The current argument is an option -- complete option names.
        COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
    else
        # Do not complete option arguments; only autocomplete positional
        # arguments (queries).
        for opt in "${opts_with_arg[@]}"; do
            [[ $opt == $prev ]] && return 1
        done

        local completion
        COMPREPLY=()
        while IFS= read -r completion; do
            # Quote spaces for `complete -W wordlist`
            COMPREPLY+=( "${completion// /\\ }" )
        done < <(ddgr --complete "$cur")
    fi

    return 0
}

complete -F _ddgr ddgr