From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14363 invoked by alias); 6 May 2015 22:03:40 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35049 Received: (qmail 25 invoked from network); 6 May 2015 22:03:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 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== X-Yahoo-Newman-Id: 858463.35307.bm@smtp110.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: kMsx5bEVM1nMvjaFCTmllTX5mNqBAsaXGa7akbuAn6vQdfc cnrrPyjWDS4UZlK9zbuB6KT_MiZBkta8_R2Mg1PvGY3qADb42lFLllrJ0_.u njiU.X2LxjZc_CkEZHz2RBR9tzglhZfGoACBA1mbhUwzAsm961afnqo5lbzP pOLmtuDuJ8j8H5mbDFSQ.ao3THhyvnCaOFU3ibA.qEa4CnxiMtz.ZN6B0UUe R3QEscxEBgCtdaJjj_kPd_5B5OSCycyo1l4vwQq_3VTDZaA64x2AYVn.SzfF aUHRU3tLt7LJK1NL3h0Q8VM5UGTLZQUNn3o3QGFqWzl3sNUYEy_Ku6jnPFdf Bz563ZX7JC4gJJGYcoGOtYikg9Swo5EeD0FeqBX2Iqt5396umIMSgq.2.kgY rF6EfkiybaEgpaauf21XOmM3ujjkOz..pPOq.2hWGB1kw7qH3LUgFLNR..zf 5xHxb8U6IAGhixCOxmdP9QQ89L46c1b5vIep.mS2Oyb02jA8kVBCCVaNI6Ug VoJ0BU_0S3i6K49tDg1AxfXFfddEQbQDb X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- In-reply-to: <20150505215445.GC2020@tarsus.local2> From: Oliver Kiddle References: <10432.1430474309@quattro> <20150505215445.GC2020@tarsus.local2> To: Zsh workers Subject: Re: PATCH: update completions for some common Unix commands MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4261.1430949496.1@quattro> Date: Wed, 06 May 2015 23:58:17 +0200 Message-ID: <4262.1430949497@quattro> 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 , \