zsh_completion: Split out zsh _coredumpctl
[thirdparty/systemd.git] / shell-completion / zsh / _systemd-coredumpctl
CommitLineData
70e104c4
WG
1#compdef systemd-coredumpctl
2
3_systemd-coredumpctl_command(){
4 local -a _systemd_coredumpctl_cmds
5 _systemd_coredumpctl_cmds=(
6 'list:List available coredumps'
7 'dump:Print coredump to std'
8 )
9 if (( CURRENT == 1 )); then
10 _describe -t commands 'systemd-coredumpctl command' _systemd_coredumpctl_cmds
11 else
12 local curcontext="$curcontext"
13 local -a _dumps
14 cmd="${${_systemd_coredumpctl_cmds[(r)$words[1]:*]%%:*}}"
15 if (( $#cmd )); then
16 # user can set zstyle ':completion:*:*:systemd-coredumpctl:*' sort no for coredumps to be ordered by date, otherwise they get ordered by pid
17 _dumps=( "${(foa)$(systemd-coredumpctl list | awk 'BEGIN{OFS=":"} /^\s/ {sub(/[[ \t]+/, ""); print $5,$0}' 2>/dev/null)}" )
18 if [[ -n "$_dumps" ]]; then
19 _describe -t pids 'coredumps' _dumps
20 else
21 _message "no coredumps"
22 fi
23 else
24 _message "no more options"
25 fi
26 fi
27}
28
29_arguments \
30 {-o,--output=}'[Write output to FILE]:output file:_files' \
31 '--no-pager[Do not pipe output into a pager]' \
32 {-h,--help}'[Show this help]' \
33 '--version[Show package version]' \
34 '*::systemd-coredumpctl commands:_systemd-coredumpctl_command'