Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

killall completion



Hello.

At first I wanted to improve killall process listing for sudo and privilege mode. But then I've decided to write own killall compdef.

It's my first compdef, so I have some problems.

I don't understand how to make completion for processes list and signals in one _arguments.

This code almost works, but processes are not completed after -SIGNAL.
Also -s or --signal should not be offered if -SIGNAL presents and vice versa. May be there are other trouble, but I don't see it.

Also it will be great to do this comdef compatible with non gnu.

I would like to improve this completion so, that it will be possible to include it in zsh source, please help me.


#compdef killall

local curcontext="$curcontext" line state ret=1
local all
all=$( (( ${funcstack[(eI)$_comps[sudo]]} || ${(%):-%(!.1.0)} )) && echo -n a )

_processes_names()
{
compadd "$expl[@]" ${${(f)"$(_call_program processes-names ps ${all}xho comm 2> /dev/null)"}:#ps}
}
_users()
{
compadd "$expl[@]" ${${(f)"$(_call_program users ps ${all}xho user 2> /dev/null)"}:#ps}
}
_groups()
{
compadd "$expl[@]" ${${(f)"$(_call_program groups ps ${all}xho group 2> /dev/null)"}:#ps}
}

_arguments -C\
    - set1 \
	'::processes-names:_processes_names' \
        ':signals:_signals -p -s' \
'(-e --exact)'{-e,--exact}'[require exact match for very long names]' \ '(-I --ignore-case)'{-I,--ignore-case}'[case insensitive process name match]' \ '(-g --process-group)'{-g,--process-group}'[kill process group instead of process]:groups:_groups' \ '(-i --interactive)'{-i,--interactive}'[ask for confirmation before killing]' \
        '(-q --quiet)'{-q,--quiet}"[don't print complaints]" \
'(-r --regexp)'{-r,--regexp}'[interpret process name as an extended regexp]' \ '(-s --signal)'{-s,--signal}'[send this signal instead of SIGTERM]:signals:_signals -s' \ '(-u --user)'{-u,--user}'[kill only process(es) the specified user owns]:users:_users' \ '(-v --verbose)'{-v,--verbose}'[report if the signal was successfully sent]' \
        '(-w --wait)'{-w,--wait}'[wait for processes to die]' \
'(-Z --context)'{-Z,--context}'[(SELinux only) specify security context]' \
    - set2 \
        '(-l --list)'{-l,--list}'[list all known signal names]' \
    - set3 \
'(-V --version)'{-V,--version}'[display version information]' && ret=0

return ret


--
sergio.



Messages sorted by: Reverse Date, Date, Thread, Author