]>
Commit | Line | Data |
---|---|---|
d611dadc MB |
1 | # systemd-coredumpctl(1) completion -*- shell-script -*- |
2 | # | |
3 | # This file is part of systemd. | |
4 | # | |
5 | # Copyright 2010 Ran Benita | |
6 | # | |
7 | # systemd is free software; you can redistribute it and/or modify it | |
8 | # under the terms of the GNU Lesser General Public License as published by | |
9 | # the Free Software Foundation; either version 2.1 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # systemd is distributed in the hope that it will be useful, but | |
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | # General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU Lesser General Public License | |
18 | # along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | __contains_word () { | |
21 | local word=$1; shift | |
22 | for w in $*; do [[ $w = $word ]] && return 0; done | |
23 | return 1 | |
24 | } | |
25 | ||
26 | __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} | |
27 | ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE | |
28 | _{P,U,G}ID _COMM _EXE _CMDLINE | |
29 | _AUDIT_{SESSION,LOGINUID} | |
30 | _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID} | |
31 | _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP | |
32 | _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT | |
33 | _KERNEL_{DEVICE,SUBSYSTEM} | |
34 | _UDEV_{SYSNAME,DEVNODE,DEVLINK} | |
35 | __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP) | |
36 | _coredumpctl() { | |
37 | local i verb comps | |
38 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
39 | local OPTS='-h --help --version --no-pager --no-legend -o --output -F --field' | |
40 | ||
41 | local -A VERBS=( | |
42 | [LIST]='list' | |
43 | [DUMP]='dump gdb' | |
44 | ) | |
45 | ||
46 | if __contains_word "$prev" '--output -o'; then | |
47 | comps=$( compgen -A file -- "$cur" ) | |
48 | compopt -o filenames | |
49 | elif __contains_word "$prev" '--FIELD -F'; then | |
50 | comps=$( compgen -W '${__journal_fields[*]}' -- "$cur" ) | |
51 | elif [[ $cur = -* ]]; then | |
52 | comps=${OPTS} | |
53 | elif __contains_word "$prev" ${VERBS[*]} && | |
54 | ! __contains_word ${COMP_WORDS[COMP_CWORD-2]} '--output -o -F --field'; then | |
55 | compopt -o nospace | |
56 | COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") ) | |
57 | return 0 | |
58 | elif [[ $cur = *=* ]]; then | |
59 | mapfile -t field_vals < <(systemd-coredumpctl -F "${prev%=}" 2>/dev/null) | |
60 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") ) | |
61 | return 0 | |
62 | elif [[ $prev = '=' ]]; then | |
63 | mapfile -t field_vals < <(systemd-coredumpctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null) | |
64 | comps=${field_vals[*]} | |
65 | else | |
66 | for ((i=0; i <= COMP_CWORD; i++)); do | |
67 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then | |
68 | verb=${COMP_WORDS[i]} | |
69 | break | |
70 | fi | |
71 | done | |
72 | ||
73 | if [[ -z $verb ]]; then | |
74 | comps=${VERBS[*]} | |
75 | elif __contains_word "$verb" ${VERBS[LIST]} ${VERBS[DUMP]}; then | |
76 | comps='' | |
77 | fi | |
78 | fi | |
79 | ||
80 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
81 | return 0 | |
82 | } | |
83 | ||
84 | complete -F _coredumpctl systemd-coredumpctl |