zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Completion: Add _bash, update _sh
@ 2018-06-09  5:15 dana
  2018-06-09  5:44 ` dana
  0 siblings, 1 reply; 2+ messages in thread
From: dana @ 2018-06-09  5:15 UTC (permalink / raw)
  To: Zsh workers

This adds full completion for bash. Hopefully that's not heresy or something.

It also updates _sh to stop completing for bash (of course), and to start
completing for ash, dash, yash, and a few others that were missing.

PS: I find zsh's own completion function a bit underwhelming. It's a good demo
of `_arguments --`, but zsh has so many options, and the --help output is so
non-descriptive about them, that relying on that just doesn't feel very nice
somehow. I'd like to improve it, but the only way i can think to achieve that is
to manually enumerate each shell option (180 of them!) and their variant name(s)
(482 total!). That's certainly doable, but idk, not sure if it's the right
direction.

PPS: I think workers # 42918 was missed:
http://www.zsh.org/mla/workers/2018/msg00722.html

dana


diff --git a/Completion/Unix/Command/_bash b/Completion/Unix/Command/_bash
new file mode 100644
index 000000000..260ca64fb
--- /dev/null
+++ b/Completion/Unix/Command/_bash
@@ -0,0 +1,85 @@
+#compdef bash
+
+local ret=1
+local -a context line state state_descr args tmp cmd
+local -A opt_args val_args
+
+cmd=( $words[1] --noprofile --norc )
+
+args=(
+  # Long options must appear before short options (take care — some of these are
+  # duplicated in the s group below!)
+  + l
+  '!--debug'
+  '--debugger[enable extended debugging mode]'
+  '(-D --dump-po-strings --dump-strings)--dump-po-strings[like -D, but display in gettext PO format]'
+  '(-D --dump-po-strings --dump-strings)--dump-strings[display strings subject to language translation]'
+  '(: -)--help[display help information]'
+  # The usual = is deliberately omitted here
+  '(--init-file --rcfile)'{--init-file,--rcfile}'[load specified file instead of ~/.bashrc]: :_files'
+  '(-l --login)--login[act as login shell]'
+  '--noediting[disable readline editing]'
+  '--noprofile[do not load /etc/profile, ~/.bash_profile, etc.]'
+  '--norc[do not load ~/.bashrc]'
+  '--posix[enable POSIX mode]'
+  '(-r --restricted)--restricted[act as restricted shell]'
+  '(: -)--version[display version information]'
+  # This is ugly, but this way the + variants have accurate descriptions. Note
+  # that bash does accept + variants of -i, -l, -s, etc., but they don't seem to
+  # actually do anything, so we don't bother with them
+  + s
+  '(l)'{'-a[','+a[do not '}'mark all functions and variables for export]'
+  '(l)'{'-B[','+B[do not '}'enable brace expansion]'
+  '(l)'{'-b[','+b[do not '}'report status of terminated background jobs immediately]'
+  '(l)'{'-C[','+C[do not '}'prevent output redirection from overwriting existing files]'
+  '(l 1 -)-c[execute specified command string]:command string:_cmdstring:argv[0]:'
+  '(l)-D[display strings subject to language translation]'
+  '(l)'{'-E[','+E[do not '}'make functions and subshells inherit ERR traps]'
+  '(l)'{'-e[','+e[do not '}'exit immediately on non-zero return]'
+  '(l)'{'-f[','+f[do not '}'disable file globbing]'
+  '(l)'{'-H[','+H[do not '}'enable history substitution]'
+  '(l)'{'-h[','+h[do not '}'hash commands]'
+  '(l)-i[act as interactive shell]'
+  '(l)'{'-k[','+k[do not '}'act on variable assignments in command arguments]'
+  '(l)-l[act as login shell]'
+  '(l)'{'-m[','+m[do not '}'enable job control]'
+  '(l)'{'-n[','+n[do not '}'read (syntax-check) commands only]'
+  '(l)*'{'-O[','+O[un'}'set specified `shopt` option]: :->shopt-options'
+  '(l)*'{'-o[','+o[un'}'set specified `set` option]: :->set-options'
+  '(l)'{'-P[','+P[do not '}'resolve cd paths]'
+  '(l)'{'-p[','+p[do not '}'enable privileged mode]'
+  '(l)-r[act as restricted shell]'
+  '(l 1 -c)-s[read commands from standard input]'
+  '(l)'{'-T[','+T[do not '}'make functions and subshells inherit DEBUG and RETURN traps]'
+  '(l)'{'-t[','+t[do not '}'exit after executing one command]'
+  '(l)'{'-u[','+u[do not '}'treat unset variables as an error during parameter expansion]'
+  '(l)'{'-v[','+v[do not '}'print shell input lines as they are read]'
+  '(l)'{'-x[','+x[do not '}'print command trace]'
+  + o
+  '(-)1:script file:_files'
+  '(-)*:: :->args'
+)
+
+_arguments -s -S -A '-*' : $args && ret=0
+
+case $state in
+  args)
+    if [[ -n ${opt_args[(i)s--[cs]]} ]]; then
+      _files && ret=0
+    else
+      _normal && ret=0
+    fi
+    ;;
+  set-options)
+    tmp=( ${(f)"$( _call_program set-options ${(q-)cmd} -c '"shopt -o"' )"} )
+    tmp=( ${tmp%%[[:space:]]*} )
+    _values -w '`set` option' $tmp && ret=0
+    ;;
+  shopt-options)
+    tmp=( ${(f)"$( _call_program shopt-options ${(q-)cmd} -c shopt )"} )
+    tmp=( ${tmp%%[[:space:]]*} )
+    _values -w '`shopt` option' $tmp && ret=0
+    ;;
+esac
+
+return ret

diff --git a/Completion/Unix/Command/_sh b/Completion/Unix/Command/_sh
index 2afb46621..39d299c58 100644
--- a/Completion/Unix/Command/_sh
+++ b/Completion/Unix/Command/_sh
@@ -1,4 +1,4 @@
-#compdef sh ksh bash csh tcsh rc
+#compdef sh ash csh dash ksh ksh88 ksh93 mksh oksh pdksh rc tcsh yash
 
 if (( CURRENT == ${words[(i)-c]} + 1 )); then
   _cmdstring


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Completion: Add _bash, update _sh
  2018-06-09  5:15 [PATCH] Completion: Add _bash, update _sh dana
@ 2018-06-09  5:44 ` dana
  0 siblings, 0 replies; 2+ messages in thread
From: dana @ 2018-06-09  5:44 UTC (permalink / raw)
  To: Zsh workers; +Cc: dana

Oh, PPPS:

On 9 Jun 2018, at 00:15, dana <dana@dana.is> wrote:
>+  args)
>+    if [[ -n ${opt_args[(i)s--[cs]]} ]]; then
>+      _files && ret=0
>+    else
>+      _normal && ret=0
>+    fi
>+    ;;

I wanted to mention (and probably should have in a comment) that my thinking
here was that you might do something like `bash /usr/bin/mycmd <tab>` and then
if mycmd had completion you'd want it handled as normal. On balance, it's
probably not *super* common for someone to explicitly call bash to execute a
script that has completion, so this might be undesirable — it'll cause custom
scripts that just happen to have the same name as a more popular command to be
completed as that command. So it could be preferable to just have an
unconditional '(-)*:: :_files' or whatever.

I don't feel strongly either way; feel free to edit if you do.

dana


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-06-09  5:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-09  5:15 [PATCH] Completion: Add _bash, update _sh dana
2018-06-09  5:44 ` dana

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).