Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: update completions for some common Unix commands

Oliver Kiddle wrote on Wed, May 06, 2015 at 23:58:17 +0200:
> Daniel Shahaf wrote:
> > Should jail names be offered as completions, rather than just as
> > descriptions?  I think most jail-related commands commands accept either
> > jname or jid to identify a jail.
> ps and pgrep both seem to require IDs but allow 0 for processes that are
> not part of a jail. Do jail-related commands accepting names have a name
> for the host system?

None do that I know of.  Neither the fully-qualified hostname nor the
base hostname works (tested with either ps and jexec).

> There's probably commands somewhere that can take either jids or names
> (jls being one example) but that's not yet handled.

How about handling those by completing just the jnames and not the jids?
After all, jnames are stable (across jail stop/start cycles) but jids

When "0" is accepted, we could complete it in addition to running jails'
names.  So for example, 'ps -J' would complete 0 plus running jnames,
and jexec would complete just jnames:

diff --git a/Completion/BSD/Command/_jexec b/Completion/BSD/Command/_jexec
new file mode 100644
index 0000000..99dcb00
--- /dev/null
+++ b/Completion/BSD/Command/_jexec
@@ -0,0 +1,7 @@
+#compdef jexec
+_arguments -s -S : \
+  '-u[host username]:host username the command will run as:_users' \
+  '-U[jail username]:jail username the command will run as' \
+  '(-)1:jail to execute the command in:_jails -o name' \
+  '*:::arguments: _normal'

> +local addhost host param desc=1
> +local -a args expl
> +zparseopts -D -K -E 0=addhost o:=param
> +param=${param[2]:-jid}
> +
> +jails=( ${${(f)"$(_call_program jails jls $param name)"}/ /:} )

Missing 'local -a jails'.



P.S. Until FreeBSD 10.1 or so, rc.d/jail would set the jname equal to
the jid, so the distinction between jname/jid completion is harder to
see in those systems.

Messages sorted by: Reverse Date, Date, Thread, Author