File: googler-completion.bash

package info (click to toggle)
googler 4.3.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 388 kB
  • sloc: python: 2,394; sh: 67; makefile: 5
file content (82 lines) | stat: -rw-r--r-- 1,748 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#
# Rudimentary Bash completion definition for googler.
#
# Author:
#   Zhiming Wang <zmwangx@gmail.com>
#

_googler () {
    COMPREPLY=()
    local IFS=$' \n'
    local cur=$2 prev=$3
    local -a opts opts_with_args
    opts=(
        -h --help
        -s --start
        -n --count
        -N --news
        -V --videos
        -c --tld
        -l --lang
        -g --geoloc
        -x --exact
        --colorize
        -C --nocolor
        --colors
        -j --first --lucky
        -t --time
        --from
        --to
        -w --site
        -e --exclude
        --unfilter
        -p --proxy
        --notweak
        --json
        --url-handler
        --show-browser-logs
        --np --noprompt
        -u --upgrade
        --include-git
        -v --version
        -d --debug
    )
    opts_with_args=(
        -s --start
        -n --count
        -c --tld
        -l --lang
        -g --geoloc
        --colorize
        --colors
        -t --time
        --from
        --to
        -w --site
        -e --exclude
        -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_args[@]}"; do
            [[ $opt == $prev ]] && return 1
        done

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

    return 0
}

complete -F _googler googler