"Fossies" - the Fresh Open Source Software Archive

Member "googler-4.3.2/auto-completion/bash/googler-completion.bash" (21 Jan 2021, 1746 Bytes) of package /linux/misc/googler-4.3.2.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 and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "googler-completion.bash": 4.2_vs_4.3.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         -g --geoloc
   22         -x --exact
   23         --colorize
   24         -C --nocolor
   25         --colors
   26         -j --first --lucky
   27         -t --time
   28         --from
   29         --to
   30         -w --site
   31         -e --exclude
   32         --unfilter
   33         -p --proxy
   34         --notweak
   35         --json
   36         --url-handler
   37         --show-browser-logs
   38         --np --noprompt
   39         -u --upgrade
   40         --include-git
   41         -v --version
   42         -d --debug
   43     )
   44     opts_with_arg=(
   45         -s --start
   46         -n --count
   47         -c --tld
   48         -l --lang
   49         -g --geoloc
   50         --colorize
   51         --colors
   52         -t --time
   53         --from
   54         --to
   55         -w --site
   56         -e --exclude
   57         -p --proxy
   58         --url-handler
   59     )
   60 
   61     if [[ $cur == -* ]]; then
   62         # The current argument is an option -- complete option names.
   63         COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
   64     else
   65         # Do not complete option arguments; only autocomplete positional
   66         # arguments (queries).
   67         for opt in "${opts_with_arg[@]}"; do
   68             [[ $opt == $prev ]] && return 1
   69         done
   70 
   71         local completion
   72         COMPREPLY=()
   73         while IFS= read -r completion; do
   74             # Quote spaces for `complete -W wordlist`
   75             COMPREPLY+=( "${completion// /\\ }" )
   76         done < <(googler --complete "$cur")
   77     fi
   78 
   79     return 0
   80 }
   81 
   82 complete -F _googler googler