| 1 |
#compdef ddgr |
| 2 |
# |
| 3 |
# Completion definition for ddgr. |
| 4 |
# |
| 5 |
# Author: |
| 6 |
# Arun Prakash Jana <[email protected]> |
| 7 |
# |
| 8 |
|
| 9 |
setopt localoptions noshwordsplit noksharrays |
| 10 |
|
| 11 |
_ddgr_query_caching_policy () { |
| 12 |
# rebuild if cache is more than a day old |
| 13 |
local -a oldp |
| 14 |
oldp=( $1(Nm+1) ) |
| 15 |
(( $#oldp )) |
| 16 |
} |
| 17 |
|
| 18 |
_ddgr_complete_query () { |
| 19 |
local prefix=$words[CURRENT] |
| 20 |
[[ -n $prefix && $prefix != -* ]] || return |
| 21 |
|
| 22 |
local cache_id=ddgr_$prefix |
| 23 |
zstyle -s :completion:${curcontext}: cache-policy update_policy |
| 24 |
[[ -z $update_policy ]] && zstyle :completion:${curcontext}: cache_policy _ddgr_query_caching_policy |
| 25 |
|
| 26 |
local -a completions |
| 27 |
if _cache_invalid $cache_id || ! _retrieve_cache $cache_id; then |
| 28 |
completions=( ${(f)"$(ddgr --complete $prefix 2>/dev/null)"} ) |
| 29 |
_store_cache $cache_id completions |
| 30 |
fi |
| 31 |
|
| 32 |
compadd $@ -- $completions |
| 33 |
} |
| 34 |
|
| 35 |
local -a args |
| 36 |
args=( |
| 37 |
'(- : *)'{-h,--help}'[show help text and exit]' |
| 38 |
'(-n --num)'{-n,--num}'[show N (0<=N<=25) results per page]:val' |
| 39 |
'(-r --reg)'{-r,--reg}'[region-specific search]:reg-lang' |
| 40 |
'(-C --nocolor)'{-C,--nocolor}'[disable color output]' |
| 41 |
'(--colors)--colors[set output colors]:six-letter string' |
| 42 |
'(-j --ducky)'{-j,--ducky}'[open the first result in web browser]' |
| 43 |
'(-t --time)'{-t,--time}'[limit search duration]:d/w/m' |
| 44 |
'(-w --site)'{-w,--site}'[search a site using DuckDuckGo]:domain' |
| 45 |
'(-x --expand)'{-x,--expand}'[show complete URL in results]' |
| 46 |
'(-p --proxy)'{-p,--proxy}'[specify proxy]:[http[s]://][user:pwd@]host[:port]' |
| 47 |
'(--unsafe)--noua[disable strict search]' |
| 48 |
'(--noua)--noua[disable user agent]' |
| 49 |
'(--json)--json[output in JSON format; implies --np]' |
| 50 |
'(--gb --gui-browser)'{--gb,--gui-browser}'[open a bang directly in gui browser]' |
| 51 |
'(--np --noprompt)'{--np,--noprompt}'[perform search and exit]' |
| 52 |
'(--rev --reverse)'{--rev,--reverse}'[list entries in reversed order]' |
| 53 |
'(--url-handler)--url-handler[cli script or utility]:url opener' |
| 54 |
'(--show-browser-logs)--show-browser-logs[do not suppress browser output]' |
| 55 |
'(- : *)'{-v,--version}'[show version number and exit]' |
| 56 |
'(-d --debug)'{-d,--debug}'[enable debugging]' |
| 57 |
'*:::query:_ddgr_complete_query' |
| 58 |
) |
| 59 |
_arguments -S -s $args |