]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/coredumpctl
journal: Serialize __MONOTONIC_TIMESTAMP metadata field as well
[thirdparty/systemd.git] / shell-completion / bash / coredumpctl
CommitLineData
f8457290 1# shellcheck shell=bash
f4bab169 2# coredumpctl(1) completion -*- shell-script -*-
db9ecf05 3# SPDX-License-Identifier: LGPL-2.1-or-later
d611dadc
MB
4#
5# This file is part of systemd.
6#
96b2fb93 7# Copyright © 2010 Ran Benita
d611dadc
MB
8#
9# systemd is free software; you can redistribute it and/or modify it
10# under the terms of the GNU Lesser General Public License as published by
11# the Free Software Foundation; either version 2.1 of the License, or
12# (at your option) any later version.
13#
14# systemd is distributed in the hope that it will be useful, but
15# WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public License
85fce6f4 20# along with systemd; If not, see <https://www.gnu.org/licenses/>.
d611dadc
MB
21
22__contains_word () {
843cfcb1
ZJS
23 local w word=$1; shift
24 for w in "$@"; do
25 [[ $w = "$word" ]] && return
26 done
d611dadc
MB
27}
28
29__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
30 ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE
31 _{P,U,G}ID _COMM _EXE _CMDLINE
32 _AUDIT_{SESSION,LOGINUID}
33 _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
34 _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
35 _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
36 _KERNEL_{DEVICE,SUBSYSTEM}
37 _UDEV_{SYSNAME,DEVNODE,DEVLINK}
38 __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
39_coredumpctl() {
843cfcb1
ZJS
40 local i verb comps
41 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
42 local OPTS='-h --help --version --no-pager --no-legend -o --output -F --field -1
a2be8be2 43 -r --reverse -S --since -U --until -D --directory -q --quiet --debugger
448ed94d 44 -A --debugger-arguments --json -n --all --file --root --image'
d611dadc 45
843cfcb1
ZJS
46 local -A VERBS=(
47 [LIST]='list info'
48 [DUMP]='dump debug'
49 )
d611dadc 50
448ed94d 51 if __contains_word "$prev" --output -o --file --image; then
843cfcb1
ZJS
52 comps=$( compgen -A file -- "$cur" )
53 compopt -o filenames
448ed94d 54 elif __contains_word "$prev" -D --directory --root; then
843cfcb1
ZJS
55 comps=$( compgen -A directory -- "$cur" )
56 compopt -o filenames
57 elif __contains_word "$prev" '--debugger'; then
58 comps=$( compgen -A command -- "$cur" )
59 compopt -o filenames
20ed583e 60 elif __contains_word "$prev" --field -F; then
843cfcb1 61 comps=$( compgen -W '${__journal_fields[*]}' -- "$cur" )
e56aa170
YW
62 elif __contains_word "$prev" '--json'; then
63 comps=$( compgen -W 'pretty short off' -- "$cur" )
843cfcb1
ZJS
64 elif [[ $cur = -* ]]; then
65 comps=${OPTS}
66 elif __contains_word "$prev" ${VERBS[*]} &&
67 ! __contains_word ${COMP_WORDS[COMP_CWORD-2]} \
68 '--output -o -D --directory -F --field --debugger'; then
69 compopt -o nospace
70 COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
71 return 0
72 elif [[ $cur = *=* ]]; then
73 mapfile -t field_vals < <(coredumpctl -F "${prev%=}" 2>/dev/null)
74 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") )
75 return 0
76 elif [[ $prev = '=' ]]; then
77 mapfile -t field_vals < <(coredumpctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
78 comps=${field_vals[*]}
79 else
80 for ((i=0; i <= COMP_CWORD; i++)); do
81 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
82 verb=${COMP_WORDS[i]}
83 break
84 fi
85 done
d611dadc 86
36ec0268 87 if [[ -z ${verb-} ]]; then
843cfcb1
ZJS
88 comps=${VERBS[*]}
89 elif __contains_word "$verb" ${VERBS[LIST]} ${VERBS[DUMP]}; then
90 comps=''
d611dadc 91 fi
843cfcb1 92 fi
d611dadc 93
843cfcb1
ZJS
94 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
95 return 0
d611dadc
MB
96}
97
f4bab169 98complete -F _coredumpctl coredumpctl