diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | Completion/Builtins/_pids | 24 | ||||
-rw-r--r-- | Completion/Builtins/_zstyle | 6 | ||||
-rw-r--r-- | Doc/Zsh/compsys.yo | 18 |
4 files changed, 28 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog index 81b459876..bd1c5ae67 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/Completion/Builtins/_pids b/Completion/Builtins/_pids index 3e1ad4758..b3ff1a058 100644 --- a/Completion/Builtins/_pids +++ b/Completion/Builtins/_pids @@ -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 diff --git a/Completion/Builtins/_zstyle b/Completion/Builtins/_zstyle index abfec06d3..3a485f0da 100644 --- a/Completion/Builtins/_zstyle +++ b/Completion/Builtins/_zstyle @@ -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' diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 4c83d45a3..65297bf70 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -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))( |