zsh-workers
 help / color / mirror / code / Atom feed
From: Eric Cook <llua@gmx.com>
To: zsh-workers@zsh.org
Subject: Re: PATCH: update completions for some common Unix commands
Date: Mon, 11 May 2015 01:32:58 -0400	[thread overview]
Message-ID: <55503F0A.9060303@gmx.com> (raw)
In-Reply-To: <20150507004059.GA1983@tarsus.local2>

Noticed the _jails patch from this thread haven't been applied yet,
besides making the jails array local, this works for me.

>> 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
> aren't.

^^which makes recalling a command from history a bit easier.
> 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:
> 

So, like this?

diff --git a/Completion/BSD/Command/_jexec b/Completion/BSD/Command/_jexec
index f065ea1..f19ae29 100644
--- a/Completion/BSD/Command/_jexec
+++ b/Completion/BSD/Command/_jexec
@@ -12,7 +12,7 @@ _jexec() {
   _arguments -s -w -A "-*" : \
     '(-U)-u[host environment user whom command runs as]:host user:_users' \
     '(-u)-U[jail environment user whom command runs as]:jail user:_users' \
-    '1:jail:_jails' \
+    '1:jail:_jails -o name' \
     '*:: : _jexec_normal'
 }

diff --git a/Completion/BSD/Command/_jls b/Completion/BSD/Command/_jls
index a6f8a7e..42c0d33 100644
--- a/Completion/BSD/Command/_jls
+++ b/Completion/BSD/Command/_jls
@@ -11,7 +11,7 @@ _arguments -C -s -w -A '-*' : \
   '-q[quote parameter value when it contains whitespace, quotes or empty string]' \
   '-s[print parameters suitable for passing to jail(8)]' \
   '-v[print a multiple-line summary per jail]' \
-  '-j[the jid or name of the jail to list]:jail:_jails' \
+  '-j[the jid or name of the jail to list]:jail:_jails -o name' \
   '*: :->parameters'

 if [[ $state == parameters ]]; then
diff --git a/Completion/BSD/Type/_jails b/Completion/BSD/Type/_jails
index 36bffec..e9d98de 100644
--- a/Completion/BSD/Type/_jails
+++ b/Completion/BSD/Type/_jails
@@ -1,5 +1,33 @@
 #autoload

-jails=( ${${${${(f)"$(_call_program jails jls -n)"}##*jid=}/ name=/:}%% *} )
+# Options:
+#
+# -0        include jid 0 as a match for the host system
+# -o param  jail parameter to complete instead of jid -
+#              e.g. name, path, ip4.addr, host.hostname

-_describe -t jails jail jails "$@"
+local addhost host param desc=1
+local -a args jails expl
+zparseopts -D -K -E 0=addhost o:=param
+param=${param[2]:-jid}
+
+jails=( ${${(f)"$(_call_program jails jls $param name)"}/ /:} )
+case $param in
+  jid) host=0 ;;
+  name)
+    host=0
+    desc=0
+  ;;
+  path)
+    host=/
+    args=( -M 'r:|/=* r:|=*' )
+  ;;
+  ip4.addr) args=( -M 'r:|.=* r:|=*' ) ;;
+esac
+[[ -n $addhost && -n $host ]] && jails+=( "$host:$HOST" )
+
+if (( desc )); then
+  _describe -t jails jail jails "$@" "$args[@]"
+else
+  _wanted jails expl jail compadd "$@" "$args[@]" - ${jails%:*}
+fi
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index 3af55a3..01f07f1 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -8,7 +8,7 @@ arguments=('-P[parent process id]:parent process id:->ppid'
      '-F[match only in process in pidfile]:files:_files'
      '-g[match only in process group ids]:group:->pgid'
      '-G[match only real group id]:group:_groups'
-     '-j[match only in processes inside jails]:jail id:->jid'
+     '-j[match only in processes inside jails]:jail id:_sequence _jails -0'
      '-J[match only in project ids]:project id:->projid'
      '-M[extract the name list from the specified core]:files:_files'
      '-N[extract the name list from the specified system]:files:_files'
diff --git a/Completion/Unix/Command/_ps b/Completion/Unix/Command/_ps
index 925f483..f5559df 100644
--- a/Completion/Unix/Command/_ps
+++ b/Completion/Unix/Command/_ps
@@ -160,7 +160,7 @@ if (( CURRENT > 1 )) && [[ $OSTYPE != solaris* || ( $OSTYPE = linux-gnu && $word
       _wanted -C option-k-1 properties expl 'property' _sequence -s , _ps_props -s - && return
     ;;
     *G) _sequence -s , _groups && return ;;
-    *J) _sequence -s , _jails && return ;;
+    *J) _sequence -s , _jails -0 -o name && return ;;
     *[MNW]) _files && return ;;
     *t)
       _wanted -C option-t-1 ttys expl tty _sequence -s , \


  reply	other threads:[~2015-05-11  5:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-01  9:58 Oliver Kiddle
2015-05-05 21:54 ` Daniel Shahaf
2015-05-06 21:58   ` Oliver Kiddle
2015-05-07  0:40     ` Daniel Shahaf
2015-05-11  5:32       ` Eric Cook [this message]
2015-05-11 11:07         ` Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55503F0A.9060303@gmx.com \
    --to=llua@gmx.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).