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