From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] new function to complete names of running process (and three example usage)
Date: Fri, 22 Jun 2018 21:11:45 +0900 [thread overview]
Message-ID: <482991CF-7732-48BD-9578-345F1D7EAB10@kba.biglobe.ne.jp> (raw)
In-Reply-To: <46A425A7-8C64-4C18-9155-0B95A9F3F0CA@dana.is>
> 2018/06/21 22:46、dana <dana@dana.is>のメール:
>
> From what i can tell, though, DTrace's execname variable (what `dtruss -n`
> matches against) seems to use pr_fname, and that's limited to 16 bytes.
dtruss accepts long process name; it just uses at most 16 bytes of it.
So I *think* it is OK (or "acceptable") to complete long process names
without truncation.
diff --git a/Completion/Unix/Type/_process_names b/Completion/Unix/Type/_process_names
new file mode 100644
index 000000000..c6108373c
--- /dev/null
+++ b/Completion/Unix/Type/_process_names
@@ -0,0 +1,44 @@
+#autoload
+#
+# complete names of running processes
+#
+# options:
+# -a: include all processes (owned by others, no tty, etc.)
+# -t: use truncated process names (e.g., those in /proc/PID/stat)
+# (this option is supported only on Linux and BSDs)
+#
+# this name has been used in _killall and documented in zshcompsys(1)
+local tagname='processes-names'
+typeset -a expl opts names all truncate
+
+zparseopts -E -D 'a=all' 't=truncate'
+(( $#all )) && opts=( -A )
+
+local hyphen=''
+# on Linux, use BSD-style option to include processes on other ttys
+[[ $OSTYPE != linux* ]] && hyphen='-'
+
+case $OSTYPE in
+ (linux*|freebsd*|openbsd*|netbsd*)
+ if (( $#truncate )); then
+ if [[ $OSTYPE == netbsd* ]]; then
+ opts+=(-co args=)
+ else
+ opts+=(${hyphen}o comm=)
+ fi
+ names=( ${${(f)"$(_call_program $tagname ps $opts 2>/dev/null)"}#-} )
+ else
+ opts+=(${hyphen}o args=)
+ names=( ${(f)"$(_call_program $tagname ps $opts 2>/dev/null )"} )
+ names=( ${${${${${names:#\[*]}%% *}%:}#-}:t}
+ ${${${(M)names:#\[*]}#\[}%]} )
+ fi
+ ;;
+ (*)
+ # ignore -t option
+ opts+=(-o comm=)
+ names=( ${${${(f)"$(_call_program $tagname ps $opts 2>/dev/null)"}#-}:t} )
+ ;;
+esac
+
+_wanted $tagname expl 'process name' compadd "$@" -F '(ps)' -a - names
prev parent reply other threads:[~2018-06-22 12:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-20 12:30 Jun T
2018-06-21 2:23 ` dana
2018-06-21 11:41 ` Jun T
2018-06-21 13:46 ` dana
2018-06-22 12:11 ` Jun T [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=482991CF-7732-48BD-9578-345F1D7EAB10@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).