From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2473 invoked by alias); 28 Jun 2018 02:02:43 -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: List-Unsubscribe: X-Seq: 43105 Received: (qmail 17434 invoked by uid 1010); 28 Jun 2018 02:02:43 -0000 X-Qmail-Scanner-Diagnostics: from mail-io0-f195.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.223.195):SA:0(-1.9/5.0):. Processed in 1.436253 secs); 28 Jun 2018 02:02:43 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIMWL_WL_MED,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=petxmhnH6kuhfGHoUx2HsgYPI857NAwnCHu9kfm0b9c=; b=0PXBiFU1DMPRiUlDGJfyM3ZevNJwoU79JmZCDjKvNRuyBVLGvok/K5E2tk0VJIBI5l OVOotXrgM1VFtyY+zwmL0wKNtmeQw+CayUA0HDUZZ+2LjoHGNkNkGOgw2J1RqHZ8Eer+ TdQ2y8QkS7uBBOxqL4P4vC41mMTLJHPGQINFhilAjIEfZuiCIZ0KK3KVcQ+sT1y1v8Ug P/XOFIE1f4YdPS9Mp+K5SMMxbgKjNBGoaLT4OVO9Mxj5gytI+qAjKiH353bvwjcA7YsE jXJ187Gr5dcwq/nJbZ8S/rTsdRrLj7ZDhrnqEhKTwfMwdR3kFOtqAII30NHuCoG4GwG6 qICQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=petxmhnH6kuhfGHoUx2HsgYPI857NAwnCHu9kfm0b9c=; b=VyLJPZRpWC7XvjU70LAQuLTQ2etPr/tQeuxunVy1X1x1hHXpofLsyeQ/6H3F+OsYsT RNtkgLs6oRkjT64ZnkVFLCktmHSYftZ5e5JCFi7p0otusaBgJ76NRyEfYC932rxWPoTJ HFRYezLCjPpEVBdE+qCiCKzgp7YP1A0lZ5lwjpCbrEgBwGZgBqN8f1lG5hCMsyaLeVMB cs2Z2Fzlwg5mZMi0USI0VhV7BmbMekVGhnWlwvUm7rrTwtY6uRbgeA1bK3+h1HFD+SLe Bw2ee58XupKhVlESEcuxx3uTvPqo2ClEhERlxRtdw7SrPUdQUalztUFnlB95bZ29ZKTp TFhw== X-Gm-Message-State: APt69E1tmmfMr6MEwuFFDEhPYpy6v/EchFrKe3UcDekuPqEsSbe2VCQM NqP9iRmWKLm/UE8yre7ImFTTfiv97Ds= X-Google-Smtp-Source: AAOMgpdVzwJnLVXPAVlpNBBlvik0C+D1zdrISq0cBsEzgBxQSsQc3AqrkTZur2qCsPDvpCT9OIwRyQ== X-Received: by 2002:a6b:d54d:: with SMTP id x13-v6mr7208587ioc.55.1530151358760; Wed, 27 Jun 2018 19:02:38 -0700 (PDT) From: dana Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.3 \(3445.6.18\)) Subject: Re: [PATCH] Completion: Improve _pgrep Date: Wed, 27 Jun 2018 21:02:37 -0500 References: To: Zsh workers In-Reply-To: Message-Id: X-Mailer: Apple Mail (2.3445.6.18) On 27 Jun 2018, at 20:39, dana wrote: >* On non-Linux systems, only complete signals as the first argument = (let me know > if there's a better way than how i did this) Of course, i realised immediately after hitting send that i could just = check CURRENT instead of adding (s) to every single option... I think this is better? dana diff --git a/Completion/Unix/Command/_pgrep = b/Completion/Unix/Command/_pgrep index ec3f8bfd0..c9d052735 100644 --- a/Completion/Unix/Command/_pgrep +++ b/Completion/Unix/Command/_pgrep @@ -1,75 +1,134 @@ #compdef pgrep pkill =20 -local curcontext=3D"$curcontext" state line ret=3D1 expl +# Notes: +# - We assume that Linux systems use procps-ng =E2=80=94 specifically, = procps-ng >=3D3.3.4 +# (which changed the behaviour of -f and added -a) +# - We don't really need to keep pgopts and pkopts separate, but it = seems like +# it should make things a bit easier to follow +# - @todo We could complete log-in classes given to -c +# - @todo We could complete routing tables given to -T + +local curcontext=3D"$curcontext" state line ret=3D1 expl pgopts pkopts = no i typeset -A opt_args -typeset -a arguments - -arguments=3D('-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:_sequence _jails = -0 -o jid' - '-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' - '-s[match only session id]:session id:->sid' - '-t[match only controlled by terminal]:terminal device:_sequence = _ttys -d' - '-T[match only in processes specified routing table in rtable]' - '-u[match only effective user id]:user:_users' - '-U[match only real user id]:user:_users' - '(-n)-o[oldest process]' - '(-o)-n[newest process]' - '-a[include process ancestors in the match list]' - '-c[print a count of matching processes]' - '-f[match against full command line]' - '-i[ignore case distinctions]' - '-I[confirmation before attempting to single each process]' - '-L[given pidfile must be locked]' - '-q[do not write anything to standard output]' - '-S[search also in system processes]' - '-v[negate matching]' - '-w[show thread ids instead of pids]' - '-x[match exactly]' - '-z[match only in zones]:zone:_zones') - -if [[ $service =3D=3D 'pgrep' ]]; then - arguments+=3D('-d[output delimiter]:delimiter:compadd ${(s\:\:)IFS}' - '-l[list name in addition to id]') -fi - -local optchars -case "$OSTYPE" in +typeset -a arguments sig_arguments aopts + +# These arguments (a) are common to all variants (like -x), (b) are the = most +# common amongst all variants (like -a), or (c) have a single = unambiguous +# meaning amongst all variants (like --help). Many of them are filtered = out or +# overridden below +arguments=3D( + '-a[include process ancestors in match list]' + '-c+[match only on specified login class]:login class' + '(-F --pidfile)'{-F+,--pidfile=3D}'[match only processes in specified = PID file]:PID file:_files' + '(-f --full)'{-f,--full}'[match against full command line]' + '(-G --group)'{-G+,--group=3D}'[match only on specified real group = IDs]: :_sequence _groups' + '(-g --pgroup)'{-g+,--pgroup=3D}'[match only on specified process = group IDs]: :->pgid' + '(: * -)'{-h,--help}'[display help information]' + '-I[request confirmation before signalling each process]' + '-i[ignore case distinctions]' + '-J+[match only on specified project IDs]: :->projid' + '-j+[match only on specified jail IDs]:jail:_sequence _jails -0 -o = jid' + '(-L --logpidfile)'{-L,--logpidfile}'[fail if PID file not locked = (with -F)]' + '(-N)-M+[extract name list from specified core]:core file:_files' + '(-M)-N+[extract name list from specified system]:system file:_files' + '(-o -n --oldest --newest)'{-n,--newest}'[match newest process]' + '(-o -n --oldest --newest)'{-o,--oldest}'[match oldest process]' + '(-P --parent)'{-P+,--parent=3D}'[match only on specified parent = process IDs]: :->ppid' + '(-l)-q[suppress normal output]' + '-S[search also in system processes (kernel threads)]' + '(-s --session)'{-s+,--session=3D}'[match only on specified process = session IDs]: :->sid' + '(ss)--signal=3D[specify signal to send to = process]:signal:(${signals\:#(EXIT|ZERR|DEBUG)})' + '-T+[match only on specified routing table]:routing table' + '(-t --terminal)'{-t+,--terminal=3D}'[match only on specified = controlling terminals]:terminal device:_sequence _ttys -d' + '(-U --uid)'{-U+,--uid=3D}'[match only on specified real user IDs]: = :_sequence _users' + '(-u --euid)'{-u+,--euid=3D}'[match only on specified effective user = IDs]: :_sequence _users' + '(-v --inverse)'{-v,--inverse}'[negate matching]' + '(-x --exact)'{-x,--exact}'[match process name or command line (with = -f) exactly]' + '--ns=3D[match only on same namespaces as specified PID]: :_pids' + '--nslist=3D[match only on specified namespaces (with = --ns)]:namespace:(ipc mnt net pid user uts)' + '(: * -)'{-V,--version}'[display version information]' + '-z+[match only on specified zone IDs]:zone:_sequence _zones' +) +[[ $service =3D=3D pgrep ]] && arguments+=3D( + '(-d --delimiter)'{-d+,--delimiter=3D}'[specify output = delimiter]:delimiter:compadd ${(s<>)IFS}' + '(-q)-l[display process name (and arguments with -f)]' + '(-w --lightweight)'{-w,--lightweight}'[show all thread IDs instead = of PID]' +) +[[ $service =3D=3D pkill ]] && arguments+=3D( + '(-e --echo)'{-e,--echo}'[display signalled process]' + '-l[display kill command]' +) + +case $OSTYPE in linux*) - optchars=3D"cflvxdnoPgsuUGtw" + # Note: We deliberately exclude -v but not --inverse from pkill + pgopts=3DacdFfGghLlnoPstUuVvwx- + pkopts=3DceFfGghLnoPstUuVx- + arguments=3D( + ${arguments:#((#s)|*\))(\*|)-[acl]*} + '(-c --count)'{-c,--count}'[display count of matching processes]' + ) + [[ $service =3D=3D pgrep ]] && arguments+=3D( + '(-a -l --list-full --list-name)'{-a,--list-full}'[display full = command line]' + '(-a -l --list-full --list-name)'{-l,--list-name}'[display = process name]' + ) ;; - freebsd*) - optchars=3D"LSafilnoqvxFGMNPUdgjstu" + dragonfly*|freebsd*) + pgopts=3DacdFfGgijLlMNnoPqSstUuvx + pkopts=3DacFfGgIijLlMNnoPstUuvx ;; openbsd*) - optchars=3D"flnoqvxdGgPsTtUu" + pgopts=3DdfGglnoPqsTtUuvx + pkopts=3DfGgIlnoPqsTtUuvx ;; darwin*) - optchars=3D"LafilnoqvxFGPUdgtu" + pgopts=3DadFfGgiLlnoPqtUuvx + pkopts=3DaFfGgIiLlnoPtUuvx ;; solaris*) - optchars=3D"flvxdnoPgsuUGJtTcz" - arguments=3D( ${arguments##-T*} ) - arguments=3D( ${arguments##-c*} ) - arguments+=3D( '-T[match only processes in task ids]:taskid:->task' = ) - arguments+=3D( '-c[match only processes in contract = ids]:taskid:->contract' ) + pgopts=3DcdfGgJlnoPsTtUuvxz + pkopts=3DcfGgJnoPsTtUuvxz + arguments=3D( + ${arguments:#((#s)|*\))(\*|)-[cT]*} + '-c+[match only on specified contract IDs]: :->contract' + '-T+[match only on specified task IDs]: :->task' + ) ;; *) - optchars=3D"flvxdnoPgsuUGt" + pgopts=3DdfGgilnPstUuvx + pkopts=3DfGgilnPstUuvx ;; esac -# Only keep relevant arguments according to $optchars. -arguments=3D( ${(M)arguments:#(|\*)(|\(*\))-[$optchars]*} - '*:process name:->pname') -if [[ $service =3D=3D 'pkill' ]]; then - arguments+=3D('-'${^signals}'[signal]') + +if [[ $service =3D=3D pgrep ]]; then + arguments=3D( ${(M)arguments:#((#s)|*\))(\*|)-[$pgopts]*} ) +else + arguments=3D( ${(M)arguments:#((#s)|*\))(\*|)-[$pkopts]*} ) + + # Signals on non-Linux systems can only be completed as the first = argument + (( CURRENT !=3D 2 )) && [[ $OSTYPE !=3D linux* ]] && no=3D'!' + + # This is used for exclusion with --signal + sig_arguments=3D( + '(ss)' ) + + # Make sure to exclude zsh-specific signals from our signal list. = This + # presumes that EXIT is always listed first and ZERR/DEBUG last =E2=80=94= see + # signames.c + for (( i =3D 1; i <=3D $#signals; i++ )); do + [[ $signals[i] =3D=3D (EXIT|ZERR|DEBUG) ]] && continue + sig_arguments+=3D( $no'(--signal)-'$signals[i] ) + # Sometimes zsh will only have the number for a signal + [[ $signals[i] =3D=3D <-> ]] || sig_arguments+=3D( + '!(--signal)-SIG'$signals[i] + '!(--signal)-'$(( i - 1 )) + ) + done fi =20 -_arguments -C -s -w $arguments && ret=3D0 +arguments+=3D( $sig_arguments + o '*: :->pname' ) + +[[ $OSTYPE =3D=3D linux* ]] || aopts+=3D( -A '*-' ) +_arguments -C -s -S $aopts : $arguments && ret=3D0 =20 case $state in (sid) @@ -87,7 +146,7 @@ case $state in sid=3D(${(uon)$(ps -A -o sid=3D)}) fi =20 - _wanted sid expl 'session id' compadd -S ',' -q -F used $sid + _wanted sid expl 'session ID' compadd -S ',' -q -F used $sid ;; =20 (ppid) @@ -101,7 +160,7 @@ case $state in ppid=3D(${(uon)$(ps -A -o ppid=3D)}) fi =20 - _wanted ppid expl 'parent process id' compadd -S ',' -q -F used = $ppid + _wanted ppid expl 'parent process ID' compadd -S ',' -q -F used = $ppid ;; =20 (pgid) @@ -115,7 +174,7 @@ case $state in pgid=3D(${(uon)$(ps -A -o pgid=3D)}) fi =20 - _wanted pgid expl 'process group id' compadd -S ',' -q -F used = $pgid + _wanted pgid expl 'process group ID' compadd -S ',' -q -F used = $pgid ;; =20 (projid) @@ -125,7 +184,7 @@ case $state in used=3D(${(s:,:)IPREFIX}) projid=3D(${(uon)$(ps -A -o project=3D)}) =20 - _wanted projid expl 'project id' compadd -S ',' -q -F used $projid + _wanted projid expl 'project ID' compadd -S ',' -q -F used $projid ;; =20 (contract) @@ -135,7 +194,7 @@ case $state in used=3D(${(s:,:)IPREFIX}) ctid=3D(${(uon)$(ps -A -o ctid=3D)}) =20 - _wanted ctid expl 'contract id' compadd -S ',' -q -F used $ctid + _wanted ctid expl 'contract ID' compadd -S ',' -q -F used $ctid ;; =20 (task) @@ -145,7 +204,7 @@ case $state in used=3D(${(s:,:)IPREFIX}) taskid=3D(${(uon)$(ps -A -o project=3D)}) =20 - _wanted taskid expl 'task id' compadd -S ',' -q -F used $taskid + _wanted taskid expl 'task ID' compadd -S ',' -q -F used $taskid ;; =20 (pname)