diff options
author | dana <dana@dana.is> | 2020-03-13 09:37:37 -0500 |
---|---|---|
committer | dana <dana@dana.is> | 2020-03-13 09:37:37 -0500 |
commit | 3f7b81e24e62d51b1af794c536bb6a97f5237625 (patch) | |
tree | 9aecf5c3d59d59577c2ed272d7907fe40cb3133a | |
parent | 778f391a3bbe47e7a00bf5ccc6bc9e79b9d413f8 (diff) | |
download | zsh-3f7b81e24e62d51b1af794c536bb6a97f5237625.tar.gz zsh-3f7b81e24e62d51b1af794c536bb6a97f5237625.tar.xz zsh-3f7b81e24e62d51b1af794c536bb6a97f5237625.zip |
45531: _sh: Complete options more accurately
Committing without handling of +x option variants (line 10) pending resolution of workers/45422
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Completion/Unix/Command/_sh | 46 |
2 files changed, 37 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog index ac59aa3e1..fddbe37c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2020-03-13 dana <dana@dana.is> + * 45531: Completion/Unix/Command/_sh: Complete options more + accurately + * 45537 (tweaked per 45550, needs 45536): Test/E02xtrace.ztst: Fix inconsistent function-name encoding in preserves-xtrace test diff --git a/Completion/Unix/Command/_sh b/Completion/Unix/Command/_sh index 39d299c58..f0f18d4bb 100644 --- a/Completion/Unix/Command/_sh +++ b/Completion/Unix/Command/_sh @@ -1,14 +1,36 @@ #compdef sh ash csh dash ksh ksh88 ksh93 mksh oksh pdksh rc tcsh yash -if (( CURRENT == ${words[(i)-c]} + 1 )); then - _cmdstring -else - local n=${words[(b:2:i)[^-]*]} - if (( n <= CURRENT )); then - compset -n $n - _alternative \ - 'files:file:_files' \ - 'commands:command:_normal' && return 0 - fi - _default -fi +local bourne argv0 +local -a args all_opts=( -{{0..9},{A..Z},{a..z}} ) + +[[ $service == (csh|?csh|fish|rc) ]] || bourne=1 + +# Bourne-style shells support +x variants +# @todo Uncomment when workers/45422 is fixed +# (( bourne )) && all_opts+=( ${all_opts/#-/+} ) +# Bourne-style shells take argv[0] as the second argument to -c +(( bourne )) && argv0=':argv[0]:' + +# All of the recognised shells support at least these arguments +args=( + "(1 -)-c[execute specified command string]: :_cmdstring$argv0" + '-e[exit immediately on non-zero return]' + '-i[act as interactive shell]' + '-l[act as login shell]' + '-x[print command trace]' + '1:script file:_files' + '*:: :_files' +) +# Bourne-style shells support -o/+o option. Not all of them support -ooption in +# the same argument, but we'll allow it here for those that do +(( bourne )) && args+=( + '-o+[set specified option]:option:' + '+o+[unset specified option]:option:' +) +# Since this is a generic function we don't know what other options these shells +# support, but we don't want them to break the ones listed above, so we'll just +# ignore any other single-alphanumeric option. Obviously this doesn't account +# for long options +args+=( '!'${^${all_opts:#(${(~j<|>)${(@M)${(@M)args#(*[\*\)]|)[+-]?}%[+-]?}})}} ) + +_arguments -s -S -A '-*' : $args |