[PATCH] compinit: improve argument parsing
dana <[email protected]>
| Newsgroups | gmane.comp.shells.zsh.devel |
|---|---|
| Message-ID | <[email protected]> |
currently compinit uses a bespoke argument-parsing method which has some issues: - it requires each option and optarg to be in a separate argument. this is not documented anywhere. worse, it silently drops an unrecognised argument, so if you try to stack the options it'll act like they're not there at all - it doesn't properly detect the optional arg to -d. for example if you give `compinit -d -w` it will take -w as the dump-file name (which will cause an error in compdump) - it allows you to give `-d $file -D` to load but not create $file, but it doesn't work the same way with `-D -d $file`. the -d option has a double meaning, it's not just the opposite of -D, so i think -D should have precedence this makes compinit use zparseopts to address all the parsing issues, and it gives -D precedence over -d so they can be used in any order dana diff --git a/Completion/compinit b/Completion/compinit index 900900644..2d6bf554a 100644 --- a/Completion/compinit +++ b/Completion/compinit @@ -77,38 +77,16 @@ setopt extendedglob typeset _i_dumpfile _i_files _i_line _i_done _i_dir _i_autodump=1 typeset _i_tag _i_file _i_addfiles _i_fail=ask _i_check=yes _i_name _i_why -while [[ $# -gt 0 && $1 = -[dDiuCw] ]]; do - case "$1" in - -d) - _i_autodump=1 - shift - if [[ $# -gt 0 && "$1" != -[dfQC] ]]; then - _i_dumpfile="$1" - shift - fi - ;; - -D) - _i_autodump=0 - shift - ;; - -i) - _i_fail=ign - shift - ;; - -u) - _i_fail=use - shift - ;; - -C) - _i_check= - shift - ;; - -w) - _i_why=1 - shift - ;; - esac -done +# note: for historical reasons it must be possible to give the optional arg to +# -d in the next parameter. zparseopts handles this by default +local -A _i_opth +zparseopts -A _i_opth -D -F - C d:: D i u w || return +(( $+_i_opth[-C] )) && _i_check= +(( $+_i_opth[-d] )) && _i_autodump=1 _i_dumpfile=$_i_opth[-d] +(( $+_i_opth[-D] )) && _i_autodump=0 +(( $+_i_opth[-i] )) && _i_fail=ign +(( $+_i_opth[-u] )) && _i_fail=use +(( $+_i_opth[-w] )) && _i_why=1 # The associative arrays containing the definitions for the commands and # services.