]>
Commit | Line | Data |
---|---|---|
f4bab169 | 1 | # coredumpctl(1) completion -*- shell-script -*- |
d611dadc MB |
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 () { | |
a72d698d DR |
21 | local w word=$1; shift |
22 | for w in "$@"; do | |
23 | [[ $w = "$word" ]] && return | |
24 | done | |
d611dadc MB |
25 | } |
26 | ||
27 | __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} | |
28 | ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE | |
29 | _{P,U,G}ID _COMM _EXE _CMDLINE | |
30 | _AUDIT_{SESSION,LOGINUID} | |
31 | _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID} | |
32 | _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP | |
33 | _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT | |
34 | _KERNEL_{DEVICE,SUBSYSTEM} | |
35 | _UDEV_{SYSNAME,DEVNODE,DEVLINK} | |
36 | __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP) | |
37 | _coredumpctl() { | |
38 | local i verb comps | |
39 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
5badf05f | 40 | local OPTS='-h --help --version --no-pager --no-legend -o --output -F --field -1 |
15710d44 | 41 | -r --reverse -S --since -U --until' |
d611dadc MB |
42 | |
43 | local -A VERBS=( | |
44 | [LIST]='list' | |
45 | [DUMP]='dump gdb' | |
46 | ) | |
47 | ||
48 | if __contains_word "$prev" '--output -o'; then | |
49 | comps=$( compgen -A file -- "$cur" ) | |
50 | compopt -o filenames | |
51 | elif __contains_word "$prev" '--FIELD -F'; then | |
52 | comps=$( compgen -W '${__journal_fields[*]}' -- "$cur" ) | |
53 | elif [[ $cur = -* ]]; then | |
54 | comps=${OPTS} | |
55 | elif __contains_word "$prev" ${VERBS[*]} && | |
56 | ! __contains_word ${COMP_WORDS[COMP_CWORD-2]} '--output -o -F --field'; then | |
57 | compopt -o nospace | |
58 | COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") ) | |
59 | return 0 | |
60 | elif [[ $cur = *=* ]]; then | |
f4bab169 | 61 | mapfile -t field_vals < <(coredumpctl -F "${prev%=}" 2>/dev/null) |
d611dadc MB |
62 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") ) |
63 | return 0 | |
64 | elif [[ $prev = '=' ]]; then | |
f4bab169 | 65 | mapfile -t field_vals < <(coredumpctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null) |
d611dadc MB |
66 | comps=${field_vals[*]} |
67 | else | |
68 | for ((i=0; i <= COMP_CWORD; i++)); do | |
69 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then | |
70 | verb=${COMP_WORDS[i]} | |
71 | break | |
72 | fi | |
73 | done | |
74 | ||
75 | if [[ -z $verb ]]; then | |
76 | comps=${VERBS[*]} | |
77 | elif __contains_word "$verb" ${VERBS[LIST]} ${VERBS[DUMP]}; then | |
78 | comps='' | |
79 | fi | |
80 | fi | |
81 | ||
82 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
83 | return 0 | |
84 | } | |
85 | ||
f4bab169 | 86 | complete -F _coredumpctl coredumpctl |