From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29020 invoked by alias); 20 Jun 2018 13:14:31 -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: 43079 Received: (qmail 19727 invoked by uid 1010); 20 Jun 2018 13:14:31 -0000 X-Qmail-Scanner-Diagnostics: from rcpt-mqugw.biglobe.ne.jp 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(133.208.100.1):SA:0(-2.6/5.0):. Processed in 1.138441 secs); 20 Jun 2018 13:14:31 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: takimoto-j@kba.biglobe.ne.jp X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Biglobe-Sender: From: Jun T Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] new function to complete names of running process (and three example usage) Message-Id: <40B3D22E-DAC5-4FC9-BFA6-2E9CEDA4AAA2@kba.biglobe.ne.jp> Date: Wed, 20 Jun 2018 21:30:25 +0900 To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3273) X-Biglobe-Spnum: 52369 _process_names completes names of running processes. I wrote this for using it from three new completions for macOS-specific = commands dtruss, fs_usage and sc_usage (also included in the patch). _process_names is tested only on macOS, Linux and {Free,Net,Open}BSD. Please test on other OS (Solaris?) if possible. diff --git a/Completion/Darwin/Command/_dtruss = b/Completion/Darwin/Command/_dtruss new file mode 100644 index 000000000..bd1ae8bc5 --- /dev/null +++ b/Completion/Darwin/Command/_dtruss @@ -0,0 +1,18 @@ +#compdef dtruss + +_arguments -s : \ + '-a[print all details]' \ + '-b+[specify dynamic variable buffer size]:buffer size (default 4m)' = \ + '-c[print system call counts]' \ + '-d[print relative timestamps]' \ + '-e[print elapsed times]' \ + '-f[follow children as they are forked]' \ + '-l[force printing of pid/lwpid per line]' \ + "-L[don't print pid/lwpid per line]" \ + '(-p :)-n+[examine processes with the specified name]: : = _process_names -a' \ + '-o[print on-cpu times]' \ + '-s[print stack backtraces]' \ + '(-n :)-p+[examine process with the specified pid]: : _pids' \ + '-t+[examine only the specified syscall]: : _sys_calls' \ + '1: : _command_names -e' \ + '*:: : _normal' diff --git a/Completion/Darwin/Command/_fs_usage = b/Completion/Darwin/Command/_fs_usage new file mode 100644 index 000000000..956816169 --- /dev/null +++ b/Completion/Darwin/Command/_fs_usage @@ -0,0 +1,28 @@ +#compdef fs_usage + +local curcontext=3D"$curcontext" state state_descr line ret=3D1 +typeset -A opt_args + +_arguments -s -C -A '-*' : \ + '-e[exclude fs_usage and the specified processes from sampling]' \ + '-w[use wider output]' \ + '*-f+[specify output filtering mode]:mode:(nework filesys pathname = exec diskio cachehit)' \ + '-b[annotate disk I/O events with BootCache info]' \ + '(-R -S -E)-t+[specify run timeout]:seconds' \ + '(-t)-R+[specify raw trace file to process]:raw trace file:_files' \ + '(-t)-S+[specify time to begin processing the trace file]:seconds' \ + '(-t)-E+[specify time to stop processing the trace file]:seconds' \ + '*: :->pid-or-pname' && ret=3D0 + +case $state in + (pid-or-pname) + if [[ -z $opt_args[-R] ]]; then + _alternative "processes:: _pids" \ + "processes-names:: _process_names -a" && ret=3D0 + else + _message 'pid or process name in the trace file' && ret=3D0 + fi + ;; +esac + +return ret diff --git a/Completion/Darwin/Command/_sc_usage = b/Completion/Darwin/Command/_sc_usage new file mode 100644 index 000000000..3a11a1bff --- /dev/null +++ b/Completion/Darwin/Command/_sc_usage @@ -0,0 +1,10 @@ +#compdef sc_usage + +_arguments -s -A '-*' : \ + '-c+[specify code file to use]:code file:_files' \ + '-e[sort output by call count]' \ + '-l[use scrolling output style instead of window updating style]' \ + '-s+[specify sampling interval]:seconds' \ + '(- :)-E[specify command path and args to excute]: = :_absolute_command_paths:*:: :_normal' \ + '1: : _alternative "processes:: _pids" + "processes-names:: _process_names -a"' diff --git a/Completion/Unix/Type/_process_names = b/Completion/Unix/Type/_process_names new file mode 100644 index 000000000..ef3a95379 --- /dev/null +++ b/Completion/Unix/Type/_process_names @@ -0,0 +1,30 @@ +#autoload +# +# completes names of running processes +# +# option -a: include all processes (owned by others, no tty, etc.) +# +typeset -a expl names all +local opts tagname +tagname=3D'processes-names' # or 'process-names' ? + +zparseopts -E -D 'a=3Dall' +(( $#all )) && opts=3D'ax' + +case $OSTYPE in + (linux*|*bsd*|dragonfly*) + # On these systems, 'ps o comm' (or 'ps co args') truncates long = process + # names. To avoid this, we get the whole command line by 'ps o = args' and + # remove arguments, but this does not work if proess names contain = spaces. + opts+=3D'o args=3D' + names=3D( ${(f)"$(_call_program $tagname ps $opts 2>/dev/null )"} ) + names=3D( ${${${${${names:#\[*]}%% *}%:}#-}:t} = ${${${(M)names:#\[*]}#\[}%]} ) + ;; + (*) + # tested only on macOS + opts+=3D'o comm=3D' + names=3D( ${${${(f)"$(_call_program $tagname ps $opts = 2>/dev/null)"}#-}:t} ) + ;; +esac + +_wanted $tagname expl 'process name' compadd "$@" -F '(ps)' -a - names