Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: update completions for some common Unix commands
- X-seq: zsh-workers 35049
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: PATCH: update completions for some common Unix commands
- Date: Wed, 06 May 2015 23:58:17 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1430949501; bh=USU8R4+HneEkoIS4BUojeZw0yBx5lF3YJQHako98pYU=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=kK7bazB9/giXwzXvP0Kl9wFEjNSa2tDC4dItSbzEQGsAmwwRNjWpZTSO64NgZDCcwxbM9GAkokwII4YNj7IgOW8VmMX0iavFKc//EyxF/TYHjPtdD2mAJHGhHQa+f8qiOrMn3mlDYxHcrQo/dpCG1lXbScs1tq+4tzF0E2rA5CJdzbY7OyZ+WC4RmVnw2zPDZ7V+KTi5DG54eRJIsaUBGxxBwVpNJLTayhRfMWMgeUSrw7Htqck3yLPQqIogIPQkTunL76qG0KClGAVs8I4dZH/jEo/iwyVGW7PdfaXmWVeC9hlDECqqchST2jvm2KxCKj9GchrJYTVCEwkF3+Lj+A==
- In-reply-to: <20150505215445.GC2020@tarsus.local2>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <10432.1430474309@quattro> <20150505215445.GC2020@tarsus.local2>
Daniel Shahaf wrote:
> Maybe use 'jls jid name' so as to not rely on 'jid' and 'name' being
> consecutive in the output of 'jls -n'?
Yes.
> 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? I was thinking it'd be good to complete also
non-running jails but that needs to parse /etc/jail.conf and other
potential sources such as ezjail so I'll leave that out for now.
Also, Eric Cook had some good suggestions (off-list) for completing
other properties such as the jail path. So the following allows _jails
to take a -0 option to complete jid 0 and -o for selecting the jail
parameter to complete such as name or path. There's probably commands
somewhere that can take either jids or names (jls being one example) but
that's not yet handled.
Oliver
diff --git a/Completion/BSD/Type/_jails b/Completion/BSD/Type/_jails
index 36bffec..5fb8bde 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 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=
+ 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..b0a0d2f 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'
@@ -93,16 +93,6 @@ case $state in
_wanted sid expl 'session id' compadd -S ',' -q -F used $sid
;;
- (jid)
- compset -P '*,'
-
- local -a used jid
- used=(${(s:,:)IPREFIX})
- jid=(${(uon)$(ps -ax -o jid=)})
-
- _wanted jid expl 'jail id' compadd -S ',' -q -F used $jid
- ;;
-
(ppid)
compset -P '*,'
diff --git a/Completion/Unix/Command/_ps b/Completion/Unix/Command/_ps
index 925f483..4106759 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 && return ;;
*[MNW]) _files && return ;;
*t)
_wanted -C option-t-1 ttys expl tty _sequence -s , \
Messages sorted by:
Reverse Date,
Date,
Thread,
Author