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

Re: PATCH: update completions for some common Unix commands



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 , \



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