Fix chromium completion

- fix wrong _alternative usage
This commit is contained in:
Shohei YOSHIDA 2026-03-08 22:12:07 +09:00
parent 5021b01fd3
commit a110107c61
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 142 additions and 134 deletions

View File

@ -33,17 +33,17 @@
# or submit itself to any jurisdiction. # or submit itself to any jurisdiction.
_arguments \ _arguments \
"--user-data-dir=[Specify the directory that user data is kept in]:directory:_path_files -/" \ "--user-data-dir=[Specify the directory that user data is kept in]:directory:_path_files -/" \
"--app=[Runs URL in app mode]:url:_urls" \ "--app=[Runs URL in app mode]:url:_urls" \
"--incognito[Open in incognito mode]" \ "--incognito[Open in incognito mode]" \
"--new-window[open in new window]" \ "--new-window[open in new window]" \
"(--no-proxy-server --proxy-auto-detect --proxy-pac-url --password-store)--proxy-server=[specify proxy server]:[<proxy-scheme>\://]<proxy-host>[\:<proxy-port>]:_chromium_proxyurls" \ "(--no-proxy-server --proxy-auto-detect --proxy-pac-url --password-store)--proxy-server=[specify proxy server]:[<proxy-scheme>\://]<proxy-host>[\:<proxy-port>]:_chromium_proxyurls" \
"--no-proxy-server[Disables the proxy server]" \ "--no-proxy-server[Disables the proxy server]" \
"--proxy-auto-detect[Autodetect proxy configuration]" \ "--proxy-auto-detect[Autodetect proxy configuration]" \
"--proxy-pac-url=[Specify proxy autoconfiguration URL]:proxy autoconfiguration url:_urls" \ "--proxy-pac-url=[Specify proxy autoconfiguration URL]:proxy autoconfiguration url:_urls" \
"--password-store=[Set the password store to use]:password store: _wanted arguments expl 'wallet store' compadd -- basic gnome kwallet" \ "--password-store=[Set the password store to use]:password store: _wanted arguments expl 'wallet store' compadd -- basic gnome kwallet" \
"--version[print version]" \ "--version[print version]" \
"*:: :{ _alternative _urls _files }" '*:: :{ _alternative "urls\:url\:_urls" "file\:file\:_files" }'
# excerpt from the chromium help message: # excerpt from the chromium help message:
# #
@ -84,128 +84,136 @@ _arguments \
_chromium_proxyurls () { _chromium_proxyurls () {
#TODO: semicolon separated urls not yet implemented #TODO: semicolon separated urls not yet implemented
# mostly copied from _urls # mostly copied from _urls
local ipre scheme host user uhosts ret=1 expl match glob suf local ipre scheme host user uhosts ret=1 expl match glob suf
local localhttp local localhttp
zstyle -a ":completion:${curcontext}:urls" local localhttp zstyle -a ":completion:${curcontext}:urls" local localhttp
local localhttp_servername="$localhttp[1]" local localhttp_servername="$localhttp[1]"
local localhttp_documentroot="$localhttp[2]" local localhttp_documentroot="$localhttp[2]"
local localhttp_userdir="$localhttp[3]" local localhttp_userdir="$localhttp[3]"
zstyle -a ":completion:${curcontext}:urls" urls urls zstyle -a ":completion:${curcontext}:urls" urls urls
if [[ $#urls -gt 1 || ( $#urls -eq 1 && ! -d $urls[1] ) ]] if [[ $#urls -gt 1 || ( $#urls -eq 1 && ! -d $urls[1] ) ]]
then then
[[ $#urls -eq 1 && -f $urls[1] ]] && urls=($(< $urls[1])) [[ $#urls -eq 1 && -f $urls[1] ]] && urls=($(< $urls[1]))
_wanted urls expl 'URL' compadd "$@" -a urls && return 0 _wanted urls expl 'URL' compadd "$@" -a urls && return 0
urls=() urls=()
fi fi
urls="$urls[1]" urls="$urls[1]"
glob=(-g '*(^/)') glob=(-g '*(^/)')
zparseopts -D -K -E 'g:=glob' zparseopts -D -K -E 'g:=glob'
ipre="$IPREFIX" ipre="$IPREFIX"
if ! compset -P '(#b)([-+.a-z0-9]#):' if ! compset -P '(#b)([-+.a-z0-9]#):'
then then
_tags -C argument prefixes _tags -C argument prefixes
while _tags while _tags
do do
while _next_label prefixes expl 'URL prefix' -S '' "$@" while _next_label prefixes expl 'URL prefix' -S '' "$@"
do do
compset -S '[^:/]*' && compstate[to_end]='' compset -S '[^:/]*' && compstate[to_end]=''
compadd "$expl[@]" http:// socks:// socks4:// socks5:// && ret=0 compadd "$expl[@]" http:// socks:// socks4:// socks5:// && ret=0
done done
(( ret )) || return 0 (( ret )) || return 0
done done
return 1 return 1
fi fi
scheme="$match[1]" scheme="$match[1]"
case "$scheme" in case "$scheme" in
(http(|s)|socks(|4|5)) if ! compset -P // (http(|s)|socks(|4|5)) if ! compset -P //
then then
_wanted -C "$scheme" prefixes expl 'end of prefix' compadd -S '' "$@" // _wanted -C "$scheme" prefixes expl 'end of prefix' compadd -S '' "$@" //
return return
fi ;; fi ;;
(file) [[ -prefix //(127.0.0.1|localhost)/ ]] && compset -P '//(127.0.0.1|localhost)' (file) [[ -prefix //(127.0.0.1|localhost)/ ]] && compset -P '//(127.0.0.1|localhost)'
[[ -prefix /// ]] && compset -P // [[ -prefix /// ]] && compset -P //
if ! compset -P // if ! compset -P //
then then
_tags -C file files _tags -C file files
while _tags while _tags
do do
while _next_label files expl 'local file' while _next_label files expl 'local file'
do do
if [[ -prefix / ]] if [[ -prefix / ]]
then then
_path_files "$expl[@]" -S '' "${glob[@]}" && ret=0 _path_files "$expl[@]" -S '' "${glob[@]}" && ret=0
_path_files "$expl[@]" -S/ -r '/' -/ && ret=0 _path_files "$expl[@]" -S/ -r '/' -/ && ret=0
elif [[ -z "$PREFIX" ]] elif [[ -z "$PREFIX" ]]
then then
compadd -S '/' -r '/' "$expl[@]" "$@" - "${PWD%/}" && ret=0 compadd -S '/' -r '/' "$expl[@]" "$@" - "${PWD%/}" && ret=0
fi fi
done done
(( ret )) || return 0 (( ret )) || return 0
done done
return 1 return 1
fi ;; fi ;;
esac esac
if ! compset -P '(#b)([^:/]#)([:/])' if ! compset -P '(#b)([^:/]#)([:/])'
then then
uhosts=($urls/$scheme/$PREFIX*$SUFFIX(/:t)) uhosts=($urls/$scheme/$PREFIX*$SUFFIX(/:t))
_tags hosts _tags hosts
while _tags while _tags
do do
while _next_label hosts expl host while _next_label hosts expl host
do do
compset -S '[:/]*' || suf="/" compset -S '[:/]*' || suf="/"
(( $#uhosts )) || _hosts -S "$suf" -r '/:' "$expl[@]" && ret=0 (( $#uhosts )) || _hosts -S "$suf" -r '/:' "$expl[@]" && ret=0
[[ "$scheme" = http ]] && uhosts=($uhosts $localhttp_servername) [[ "$scheme" = http ]] && uhosts=($uhosts $localhttp_servername)
compadd -S "$suf" -r '/:' "$expl[@]" -a uhosts && ret=0 compadd -S "$suf" -r '/:' "$expl[@]" -a uhosts && ret=0
done done
(( ret )) || return 0 (( ret )) || return 0
done done
return 1 return 1
fi fi
host="$match[1]" host="$match[1]"
[[ $match[2] = ':' ]] && ! compset -P '<->/' && _message -e ports 'port number' && return 0 [[ $match[2] = ':' ]] && ! compset -P '<->/' && _message -e ports 'port number' && return 0
_tags remote-files files || return 1 _tags remote-files files || return 1
if [[ "$localhttp_servername" = "$host" ]] if [[ "$localhttp_servername" = "$host" ]]
then then
if compset -P \~ if compset -P \~
then then
if ! compset -P '(#b)([^/]#)/' if ! compset -P '(#b)([^/]#)/'
then then
_users -S/ "$@" _users -S/ "$@"
return return
fi fi
user="$match[1]" user="$match[1]"
while _tags while _tags
do do
while _next_label files expl 'local file' while _next_label files expl 'local file'
do do
_path_files "$expl[@]" "$@" -W ~$user/$localhttp_userdir "${glob[@]}" && ret=0 _path_files "$expl[@]" "$@" -W ~$user/$localhttp_userdir "${glob[@]}" && ret=0
_path_files -S/ -r '/' "$expl[@]" -W ~$user/$localhttp_userdir-/ && ret=0 _path_files -S/ -r '/' "$expl[@]" -W ~$user/$localhttp_userdir-/ && ret=0
done done
(( ret )) || return 0 (( ret )) || return 0
done done
else else
while _tags while _tags
do do
while _next_label files expl 'local file' while _next_label files expl 'local file'
do do
_path_files "$expl[@]" "$@" -W $localhttp_documentroot "${glob[@]}" && ret=0 _path_files "$expl[@]" "$@" -W $localhttp_documentroot "${glob[@]}" && ret=0
_path_files -S/ -r '/' "$expl[@]" -W $localhttp_documentroot -/ && ret=0 _path_files -S/ -r '/' "$expl[@]" -W $localhttp_documentroot -/ && ret=0
done done
(( ret )) || return 0 (( ret )) || return 0
done done
fi fi
else else
while _tags while _tags
do do
(( $#urls )) && while _next_label files expl 'local file' (( $#urls )) && while _next_label files expl 'local file'
do do
_path_files "$expl[@]" "$@" -W $urls/$scheme/$host "${glob[@]}" && ret=0 _path_files "$expl[@]" "$@" -W $urls/$scheme/$host "${glob[@]}" && ret=0
_path_files -S/ -r '/' "$expl[@]" -W $urls/$scheme/$host -/ && ret=0 _path_files -S/ -r '/' "$expl[@]" -W $urls/$scheme/$host -/ && ret=0
done done
[[ $scheme = (scp|sftp) ]] && _requested remote-files && _remote_files -h $host -- ssh && ret=0 [[ $scheme = (scp|sftp) ]] && _requested remote-files && _remote_files -h $host -- ssh && ret=0
(( ret )) || return 0 (( ret )) || return 0
done done
fi fi
return $ret return $ret
} }
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et