From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20569 invoked by alias); 11 May 2015 05:33:12 -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: 35081 Received: (qmail 6341 invoked from network); 11 May 2015 05:33:09 -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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Message-ID: <55503F0A.9060303@gmx.com> Date: Mon, 11 May 2015 01:32:58 -0400 From: Eric Cook User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: zsh-workers@zsh.org Subject: Re: PATCH: update completions for some common Unix commands References: <10432.1430474309@quattro> <20150505215445.GC2020@tarsus.local2> <4262.1430949497@quattro> <20150507004059.GA1983@tarsus.local2> In-Reply-To: <20150507004059.GA1983@tarsus.local2> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:rrjFPaSosda43fISHnnFq0VyxUIRGLoM/OO92zMwZ8hSsIPC3jt RmACZhWFbSBdLkNRo6iURtM/MZH6NBC8fRng8YnDJocDTUtpTRTgN8RxKcoBpq7DdS7+wur jIvtDIE0QKW+PsaSsa0XtjkDpdh7MqncY+ivXtnREByFK5CcrXUWoIsl+TUVz/5D08usku1 b6gc4zumwYeYBjklMPSEg== X-UI-Out-Filterresults: notjunk:1; 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 , \