1#compdef wget
2
3local curcontext="$curcontext" state line expl
4typeset -A opt_args
5
6_arguments -C -s \
7  '(- *)'{--version,-V}'[display version info]' \
8  '(- *)'{--help,-h}'[display help]' \
9  '(--background -b)'{--background,-b}'[run in background]' \
10  '(--execute -e)'{--execute=,-e+}'[execute .wgetrc command]:.wgetrc command' \
11  '(--output-file -o --append-output -a)'{--output-file=,-o+}'[specify output logfile]:log file to output:_files' \
12  '(--append-output -a --output-file -o)'{--append-output=,-a+}'[specify output logfile to append to]:log file to append:_files' \
13  '(--debug -d)'{--debug,-d}'[turn on debug output]' \
14  '(--quiet -q --verbose -v --no-verbose -nv)'{--quiet,-q}'[turn off output]' \
15  '(--quiet -q --verbose -v --no-verbose -nv)'{--verbose,-v}'[turn on verbose output]' \
16  '*-n+[turn off flags]:flags:->noflags' \
17  '--report-speed=:type:(bits)' \
18  '(--input-file -i)'{--input-file=,-i+}'[specify input file]:file containing URLs:_files' \
19  '--input-metalink=[download files covered in local Metalink file]:file:_files' \
20  '(--force-html -F)'{--force-html,-F}'[treat input file as html]' \
21  '(--base -B)'{--base=,-B+}'[prepend URL to relative links]:base URL:_urls' \
22  '--config=[specify config file]:config file:_files' \
23  '(--config)--no-config' '--rejected-log=:file:_files' \
24  '(--tries -t)'{--tries=,-t+}'[set number of retries]:number of retries' \
25  '--retry-connrefused[retry even if connection is refused]' \
26  '--retry-on-http-error=[specify list of HTTP errors to retry]:http error' \
27  '(--output-document -O)'{--output-document=,-O+}'[specify file to write documents to]:output file:_files' \
28  '(--continue -c)'{--continue,-c}'[continue getting an existing file]'  \
29  '--start-pos=:offset' '--show-progress' \
30  '--progress=[set progress gauge type]:gauge type:->gauge' \
31  '(--timestamping -N)'{--timestamping,-N}'[retrieve only files newer than existing]' \
32  '--no-if-modified-since' \
33  "--no-use-server-timestamps[don't set the local file's timestamp by the one on the server]" \
34  '(--server-response -S)'{--server-response,-S}'[print server response]' \
35  "--spider[don't download anything]" \
36  '(--timeout -T)'{--timeout=,-T+}'[set all timeout values]:timeout (seconds)' \
37  '(--timeout -T)--dns-timeout=[set the DNS lookup timeout]:DNS lookup timeout (seconds)' \
38  '(--timeout -T)--connect-timeout=[set the connect timeout]:connect timeout (seconds)' \
39  '(--timeout -T)--read-timeout=[set the read timeout]:read timeout (seconds)' \
40  '(--wait -w)'{--wait=,-w+}'[specify wait between retrievals]:time (seconds)' \
41  '(--random-wait)--waitretry=:time (seconds)' \
42  '(--waitretry)--random-wait[random wait time between retrievals]' \
43  '--no-proxy[explicitly turn off proxy]' \
44  '(--quota -Q)'{--quota=,-Q+}'[set retrieval quota]:number' \
45  '--bind-address=[specify address to bind to (hostname or IP)]:bind address:_bind_addresses' \
46  '--limit-rate=[specify limit to download rate]:download rate limit' \
47  '--no-dns-cache[disable caching DNS lookups]' \
48  '--restrict-file-names=[restrict chars in file names to ones OS allows]:OS:->restrict' \
49  '--ignore-case[ignore case when matching files/directories]' \
50  '(-4 --inet4-only -6 --inet6-only)'{-4,--inet4-only}'[connect only to IPv4 addresses]' \
51  '(-4 --inet4-only -6 --inet6-only)'{-6,--inet6-only}'[connect only to IPv6 addresses]' \
52  '--prefer-family=[connect first to addresses of specified family]:address family:(IPv6 IPv4 none)' \
53  '(--http-user --ftp-user)--user[set both ftp and http user]:user' \
54  '(--http-password --ftp-password)--password[set both ftp and http password]:password' \
55  '(--password --http-password --ftp-password)--ask-password:[prompt for passwords]' \
56  '--use-askpass=:command:_command_names -e' \
57  '--no-iri[turn off IRI support]' \
58  '--local-encoding=[specify local encoding for IRIs]:encoding' \
59  '--remote-encoding=[specify default remote encoding]:encoding' \
60  '--unlink[remove file before clobber]' \
61  '--keep-badhash[Keep files with checksum mismatch (append .badhash)]' \
62  '--metalink-index=[metalink application/metalink4+xml metaurl ordinal]:number' \
63  '--metalink-over-http[use Metalink metadata from HTTP response headers]' \
64  '--preferred-location[preferred location for Metalink resources]' \
65  '--xattr[turn on storage of metadata in extended file attributes]' \
66  '(-nd --no-directories)'{-nd,--no-directories}"[don't create directories]" \
67  '(--force-directories -x)'{--force-directories,-x}'[force creation of directories]' \
68  '(-nH --no-host-directories)'{-nH,--no-host-directories}"[don't create host directories]" \
69  '--protocol-directories[use protocol name in directories]' \
70  '(--directory-prefix -P)'{--directory-prefix=,-P+}'[specify prefix to save files to]:prefix:_files -/' \
71  '--cut-dirs=:number:' \
72  '(--user)--http-user=:user' \
73  '(--password --ask-password)--http-password=:password' \
74  '--no-cache[disallow server-cached data]' \
75  '--default-page=[specify default page name, normally index.html]:default page [index.html]' \
76  '(--adjust-extension -E)'{--adjust-extension,-E}'[save all HTML/CSS documents with proper extensions]' \
77  "--ignore-length[ignore \`Content-Length' header field]" \
78  '*--header=[send a custom HTTP header]:header:->header' \
79  '--compression=:compression:(auto gzip none)' \
80  '--max-redirect=:number' \
81  '--proxy-user=:user' \
82  '--proxy-password=:password' \
83  '--referer=:URL:_urls' \
84  '--save-headers[save http headers]' \
85  '(--user-agent -U)'{--user-agent=,-U+}'[specify user agent to identify as]:user-agent' \
86  '--no-http-keep-alive[disable HTTP keep-alive]' \
87  '--no-cookies[turn cookies off]' \
88  '--load-cookies=[specify file to load cookies from]:cookie file:_files' \
89  '--save-cookies=[specify file to save cookies to]:cookie file:_files' \
90  '--keep-session-cookies[load and save session cookies]' \
91  '--post-data=[use the POST method with specified data]:data to send' \
92  '--post-file=[use the POST method; sending contents of a file]:file:_files' \
93  '--method=[use specified HTTP method]:method:(GET POST HEAD DELETE)' \
94  '(--body-file)--body-data=[send string as data]:string' \
95  '(--body-data)--body-file=[send contents of file]:file:_files' \
96  '--content-disposition[honor the Content-Disposition header when choosing local file names]'  \
97  '--content-on-error[output received content on server errors]' \
98  "--auth-no-challenge[send basic HTTP authentication without first waiting for server's challenge]" \
99  '--secure-protocol=[choose secure protocol]:protocol:(SSLv2 SSLv3 TLSv1 TLSv1_1 TLSv1_2 PFS)' \
100  --https-only \
101  "--no-check-certificate[don't check the server certificate]" \
102  '--certificate=[specify client certificate]:client certificate file:_files' \
103  '--certificate-type=[specify client certificate type]:certificate type:(PEM DER)' \
104  '--private-key=[specify private key file]:key file:_files' \
105  '--private-key-type=[specify private key type]:key type:key type:(PEM DER)' \
106  "--ca-certificate=[specify file with bundle of CA's]:file:_files" \
107  "--ca-directory=[specify dir where hash list of CA's are stored]:directory:_directories" \
108  '--crl-file=[specify file with bundle of CRLs]:file:_files' \
109  '--pinnedpubkey=:file:_files' \
110  '!--random-file=:file:_files' \
111  '--egd-file=[specify filename of EGD socket]:file:_files' \
112  '--ciphers=[set the priority string (GnuTLS) or cipher list string (OpenSSL) directly]:string' \
113  '--no-hsts[disable HSTS]' \
114  '--hsts-file[specify path of HSTS database]:file:_files' \
115  '(--user)--ftp-user=:user' \
116  '(--password --ask-password)--ftp-password=:password' \
117  "--no-remove-listing[don't remove \`.listing' files]" \
118  '--no-glob[turn off FTP file name globbing]' \
119  '--no-passive-ftp' \
120  '--preserve-permissions[preserve remote file permissions with ftp]' \
121  --retr-symlinks --ftps-implicit --ftps-resume-ssl \
122  --ftps-clear-data-connection --ftps-fallback-to-ftp \
123  '--warc-file=:file:_files' --warc-header=:string --warc-max-size=:number \
124  --warc-cdx --warc-dedup=:file:_files --no-warc-compression --no-warc-digests \
125  --no-warc-keep-log --warc-tempdir=:directory:_directories \
126  '(--recursive -r)'{--recursive,-r}'[recurse subdirectories]' \
127  '(--level -l)'{--level=,-l+}'[specify maximum recursion depth]:level' \
128  '--delete-after' \
129  '(--convert-links -k)'{--convert-links,-k}'[convert links to be relative]' \
130  --convert-file-only \
131  '--backups=:max backups' \
132  '(--backup-converted -K)'{--backup-converted,-K}'[backup files before conversion]' \
133  '(--mirror -m -r -N -l)'{--mirror,-m}'[mirror (-r -N -l inf --no-remove-listing)]' \
134  '(--page-requisites -p)'{--page-requisites,-p}'[get all images needed to display page]' \
135  '--strict-comments[turn on strict (SGML) handling of HTML comments]' \
136  '(--accept -A)'{--accept=,-A+}'[specify accepted extensions]:extensions' \
137  '(--reject -R)'{--reject=,-R+}'[specify rejected extensions]:extensions' \
138  --{accept,reject}-regex=:regex '--regex-type=:regex type:(posix pcre)' \
139  '(--domains -D)'{--domains=,-D+}'[specify accepted domains]:domains:_domains' \
140  '--exclude-domains=:rejected domains:_domains' \
141  '--follow-ftp' \
142  '--follow-tags=:HTML tags:' \
143  '--ignore-tags=[specify ignored HTML tags]:HTML tags' \
144  '(--span-hosts -H)'{--span-hosts,-H}'[span hosts]' \
145  '(--relative -L)'{--relative,-L}'[follow relative links only]' \
146  '(--include-directories -I)'{--include-directories=,-I+}'[include directories]:allowed directories' \
147  '--trust-server-names' \
148  '(--exclude-directories -X)'{--exclude-directories=,-X+}'[exclude directories]:excluded directories' \
149  '(-np --no-parent)'{-np,--no-parent}"[don't ascend to parent directory]" \
150  '--no-verbose' \
151  '--no-clobber' \
152  '--no-netrc' \
153  '--no-use-server-timestamps[do not set timestamp to server provided value]' \
154  '--htmlify=:htmlify:' \
155  '--no:no:->noflags' \
156  '*:URL:_urls' && return 0
157
158case "$state" in
159  gauge)
160    _values -S : 'progress gauge type' \
161      'dot:style:(default binary mega giga micro)' \
162      'bar:force:(force)'
163  ;;
164  noflags)
165    _values -s '' 'option' \
166      'v[non verbose]' \
167      'H[no host directories]' \
168      'd[no directories]' \
169      'c[no clobber]' \
170      'p[no parent]'
171  ;;
172  restrict)
173    _values -s , 'filename char restriction' \
174      '(windows)unix' \
175      '(unix)windows' \
176      '(unix windows)nocontrol' \
177      ascii \
178      '(uppercase)lowercase' \
179      '(lowercase)uppercase'
180  ;;
181  header)
182    local -a headers
183    local suf=': '
184    compquote suf
185    headers=(
186             Accept{,-{Charset,Encoding,Language,Datetime}}
187             Authorization
188             Cache-Control
189             Connection
190             Cookie
191             Content-{Length,MD5,Type}
192             Date
193             Expect
194             From
195             Host
196             If-Match
197             If-Modified-Since
198             If-None-Match
199             If-Range
200             If-Unmodified-Since
201             Max-Forwards
202             Pragma
203             Proxy-Authorization
204             Range
205             Referer
206             TE
207             Upgrade
208             User-Agent
209             Via
210             Warning
211             X-Requested-With
212             X-Do-Not-Track
213             DNT
214             X-Forwarded-For
215             X-ATT-DeviceId
216             X-Wap-Profile
217             )
218    _wanted headers expl 'HTTP header' compadd -S $suf -a headers
219  ;;
220esac
221