"Fossies" - the Fresh Open Source Software Archive

Member "googler-4.1/auto-completion/bash/googler-completion.bash" (30 Apr 2020, 1664 Bytes) of package /linux/misc/googler-4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "googler-completion.bash": 4.0_vs_4.1.

    1 #
    2 # Rudimentary Bash completion definition for googler.
    3 #
    4 # Author:
    5 #   Zhiming Wang <zmwangx@gmail.com>
    6 #
    7 
    8 _googler () {
    9     COMPREPLY=()
   10     local IFS=$' \n'
   11     local cur=$2 prev=$3
   12     local -a opts opts_with_args
   13     opts=(
   14         -h --help
   15         -s --start
   16         -n --count
   17         -N --news
   18         -V --videos
   19         -c --tld
   20         -l --lang
   21         -x --exact
   22         --colorize
   23         -C --nocolor
   24         --colors
   25         -j --first --lucky
   26         -t --time
   27         --from
   28         --to
   29         -w --site
   30         --unfilter
   31         -p --proxy
   32         --notweak
   33         --json
   34         --url-handler
   35         --show-browser-logs
   36         --np --noprompt
   37         -u --upgrade
   38         --include-git
   39         -v --version
   40         -d --debug
   41     )
   42     opts_with_arg=(
   43         -s --start
   44         -n --count
   45         -c --tld
   46         -l --lang
   47         --colorize
   48         --colors
   49         -t --time
   50         --from
   51         --to
   52         -w --site
   53         -p --proxy
   54         --url-handler
   55     )
   56 
   57     if [[ $cur == -* ]]; then
   58         # The current argument is an option -- complete option names.
   59         COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
   60     else
   61         # Do not complete option arguments; only autocomplete positional
   62         # arguments (queries).
   63         for opt in "${opts_with_arg[@]}"; do
   64             [[ $opt == $prev ]] && return 1
   65         done
   66 
   67         local completion
   68         COMPREPLY=()
   69         while IFS= read -r completion; do
   70             # Quote spaces for `complete -W wordlist`
   71             COMPREPLY+=( "${completion// /\\ }" )
   72         done < <(googler --complete "$cur")
   73     fi
   74 
   75     return 0
   76 }
   77 
   78 complete -F _googler googler