mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-11-02 06:40:55 +01:00
call ps only once and be more intelligent when finding the PIDs (12640)
This commit is contained in:
parent
a070f9bb56
commit
0352b80797
4 changed files with 28 additions and 24 deletions
|
|
@ -1,5 +1,9 @@
|
|||
2000-08-15 Sven Wischnowsky <wischnow@zsh.org>
|
||||
|
||||
* 12640: Completion/Builtins/_pids, Completion/Builtins/_zstyle,
|
||||
Doc/Zsh/compsys.yo: call ps only once and be more intelligent when
|
||||
finding the PIDs
|
||||
|
||||
* 12635: Completion/Builtins/_pids: small improvement to allow
|
||||
lists where the pid is not in the first column
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
# If given the `-m <pattern>' option, this tries to complete only pids
|
||||
# of processes whose command line match the `<pattern>'.
|
||||
|
||||
local out list expl match desc listargs args all nm ret=1
|
||||
local out pids index list expl match desc listargs args all nm ret=1
|
||||
|
||||
_tags processes || return 1
|
||||
|
||||
|
|
@ -22,24 +22,26 @@ fi
|
|||
|
||||
zstyle -s ":completion:${curcontext}:processes" command args
|
||||
|
||||
out="$(_call processes ps 2>/dev/null)"
|
||||
out=( "${(@f)$(_call processes ps 2>/dev/null)}" )
|
||||
desc="$out[1]"
|
||||
out=( "${(@M)out[2,-1]:#${~match}}" )
|
||||
|
||||
if [[ "$desc" = (#i)(|*[[:blank:]])pid(|[[:blank:]]*) ]]; then
|
||||
index="${#desc[1,(r)(#i)[[:blank:]]pid]}"
|
||||
pids=( "${(@)${(@M)out#${(l:index::?:)~:-}[^[:blank:]]#}##*[[:blank:]]}" )
|
||||
else
|
||||
pids=( "${(@)${(@M)out##[^0-9]#[0-9]#}##*[[:blank:]]}" )
|
||||
fi
|
||||
|
||||
if zstyle -T ":completion:${curcontext}:processes" verbose; then
|
||||
zstyle -s ":completion:${curcontext}:processes-list" command listargs
|
||||
(( $#listargs )) || listargs=( "$args[@]" )
|
||||
if [[ "$listargs" = "$args" ]]; then
|
||||
list=("${(@Mr:COLUMNS-1:)${(f@)out}[2,-1]:#${~match}}")
|
||||
else
|
||||
list=("${(@Mr:COLUMNS-1:)${(f@)$(_call processes-list ps 2>/dev/null)}[2,-1]:#${~match}}")
|
||||
fi
|
||||
list=( "${(@Mr:COLUMNS-1:)out}" )
|
||||
desc=(-ld list)
|
||||
else
|
||||
desc=()
|
||||
fi
|
||||
|
||||
_wanted processes expl 'process ID' \
|
||||
compadd "$@" "$desc[@]" "$all[@]" - \
|
||||
${${${(M)${(f)"${out}"}[2,-1]:#${~match}}## #}%% *} && ret=0
|
||||
compadd "$@" "$desc[@]" "$all[@]" -a pids && ret=0
|
||||
|
||||
if [[ -n "$all" ]]; then
|
||||
zstyle -s ":completion:${curcontext}:processes" insert-ids out || out=menu
|
||||
|
|
|
|||
|
|
@ -103,9 +103,9 @@ displays expansions extensions files fonts functions globbed-files groups
|
|||
history-words hosts indexes jobs keymaps keysyms local-directories
|
||||
libraries limits manuals maps messages modifiers modules my-accounts
|
||||
named-directories names nicknames options original other-accounts packages
|
||||
parameters path-directories paths pods ports prefixes processes ps regex
|
||||
sequences sessions signals strings tags targets types urls users values
|
||||
warnings widgets windows zsh-options)
|
||||
parameters path-directories paths pods ports prefixes processes
|
||||
processes-names ps regex sequences sessions signals strings tags targets
|
||||
types urls users values warnings widgets windows zsh-options)
|
||||
|
||||
_arguments -C ':context:->contexts' ':style:->styles' '*:argument:->style-arg'
|
||||
|
||||
|
|
|
|||
|
|
@ -744,11 +744,6 @@ kindex(processes, completion tag)
|
|||
item(tt(processes))(
|
||||
for process identifiers
|
||||
)
|
||||
kindex(processes-list, completion tag)
|
||||
item(tt(processes-list))(
|
||||
used to look up the tt(command) style when generating the list to
|
||||
display for process identifiers
|
||||
)
|
||||
kindex(processes-names, completion tag)
|
||||
item(tt(processes-names))(
|
||||
used to look up the tt(command) style when generating the names of
|
||||
|
|
@ -934,11 +929,14 @@ example to avoid calling a shell function with the same name as an external
|
|||
command.
|
||||
|
||||
As an example, the function generating process IDs as matches uses this
|
||||
style with the tt(processes) tag to generate the IDs to complete and when
|
||||
the tt(verbose) style is `true', it uses this style with the
|
||||
tt(processes-list) tag to generate the strings to display. When using
|
||||
different values for these two tags one should ensure that the process
|
||||
IDs appear in the same order in both lists.
|
||||
style with the tt(processes) tag to generate the IDs to complete and
|
||||
the list of processes to display (if the tt(verbose) style is `true').
|
||||
The list produced by the command should look like the output of the
|
||||
tt(ps) command. The first line is not displayed, but is searched for
|
||||
the string `tt(PID)' (or `tt(pid)') to find the position of the
|
||||
process IDs in the following lines. If the line does not contain
|
||||
`tt(PID)', the first numbers in each of the other lines are taken as the
|
||||
process IDs to complete.
|
||||
)
|
||||
kindex(completer, completion style)
|
||||
item(tt(completer))(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue