1 # journalctl(1) completion -*- shell-script -*-
3 # This file is part of systemd.
5 # Copyright 2010 Ran Benita
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.
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.
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/>.
21 local w word=$1; shift
23 [[ $w = "$word" ]] && return
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 _CAP_EFFECTIVE _AUDIT_{SESSION,LOGINUID}
31 _SYSTEMD_{CGROUP,SESSION,{,USER_}UNIT,OWNER_UID,SLICE}
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)
38 __syslog_priorities=(emerg alert crit err warning notice info debug)
41 local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
43 [STANDALONE]='-a --all --full --system --user
44 --disk-usage -f --follow --header
45 -h --help -l --local --new-id128 -m --merge --no-pager
46 --no-tail -q --quiet --setup-keys --this-boot --verify
47 --version --list-catalog --update-catalog --list-boots
48 --show-cursor --dmesg -k --pager-end -e -r --reverse
49 --utc -x --catalog --no-full --force --dump-catalog
50 --flush --rotate --sync'
51 [ARG]='-b --boot --this-boot -D --directory --file -F --field
52 -o --output -u --unit --user-unit -p --priority
53 --vacuum-size --vacuum-time'
54 [ARGUNKNOWN]='-c --cursor --interval -n --lines -S --since -U --until
55 --after-cursor --verify-key -t --identifier
59 if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
61 --boot|--this-boot|-b)
62 comps=$(journalctl -F '_BOOT_ID' 2>/dev/null)
65 comps=$(compgen -d -- "$cur")
69 comps=$(compgen -f -- "$cur")
73 comps='short short-iso short-precise short-monotonic verbose export json json-pretty json-sse cat'
76 comps=${__journal_fields[*]}
79 comps=${__syslog_priorities[*]}
82 comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null)
85 comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
91 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
95 if [[ $cur = -* ]]; then
96 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
98 elif [[ $cur = *=* ]]; then
99 mapfile -t field_vals < <(journalctl -F "${prev%=}" 2>/dev/null)
100 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") )
101 elif [[ $cur = /dev* ]]; then
103 COMPREPLY=( $(compgen -f -- "${cur}") )
104 elif [[ $cur = /* ]]; then
105 # Append /dev/ to the list of completions, so that
106 # after typing /<TAB><TAB> the user sees /dev/ as one
107 # of the alternatives. Later on the rule above will
108 # take care of showing device files in /dev/.
109 mapfile -t field_vals < <(journalctl -F "_EXE" 2>/dev/null; echo '/dev/')
110 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur}") )
111 if [[ "${COMPREPLY[@]}" = '/dev/' ]]; then
113 COMPREPLY=( $(compgen -f -- "${cur}") )
115 elif [[ $prev = '=' ]]; then
116 mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
117 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") )
120 COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
124 complete -F _journalctl journalctl