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
29 (machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \
30 { while read a b; do echo " $a"; done; } | sort -u;
33 __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
34 ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE
35 _{P,U,G}ID _COMM _EXE _CMDLINE
36 _CAP_EFFECTIVE _AUDIT_{SESSION,LOGINUID}
37 _SYSTEMD_{CGROUP,SESSION,{,USER_}UNIT,OWNER_UID,SLICE}
38 _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
39 _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
40 _KERNEL_{DEVICE,SUBSYSTEM}
41 _UDEV_{SYSNAME,DEVNODE,DEVLINK}
42 __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
44 __syslog_priorities=(emerg alert crit err warning notice info debug)
47 local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
49 [STANDALONE]='-a --all --full --system --user
50 --disk-usage -f --follow --header
51 -h --help -l --local --new-id128 -m --merge --no-pager
52 --no-tail -q --quiet --setup-keys --this-boot --verify
53 --version --list-catalog --update-catalog --list-boots
54 --show-cursor --dmesg -k --pager-end -e -r --reverse
55 --utc -x --catalog --no-full --force --dump-catalog
56 --flush --rotate --sync'
57 [ARG]='-b --boot --this-boot -D --directory --file -F --field
58 -M --machine -o --output -u --unit --user-unit -p --priority
59 --vacuum-size --vacuum-time'
60 [ARGUNKNOWN]='-c --cursor --interval -n --lines -S --since -U --until
61 --after-cursor --verify-key -t --identifier
65 if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
67 --boot|--this-boot|-b)
68 comps=$(journalctl -F '_BOOT_ID' 2>/dev/null)
71 comps=$(compgen -d -- "$cur")
75 comps=$(compgen -f -- "$cur")
79 comps='short short-iso short-precise short-monotonic verbose export json json-pretty json-sse cat'
82 comps=${__journal_fields[*]}
85 comps=$( __get_machines )
88 comps=${__syslog_priorities[*]}
91 comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null)
94 comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
100 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
104 if [[ $cur = -* ]]; then
105 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
107 elif [[ $cur = *=* ]]; then
108 mapfile -t field_vals < <(journalctl -F "${prev%=}" 2>/dev/null)
109 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") )
110 elif [[ $cur = /dev* ]]; then
112 COMPREPLY=( $(compgen -f -- "${cur}") )
113 elif [[ $cur = /* ]]; then
114 # Append /dev/ to the list of completions, so that
115 # after typing /<TAB><TAB> the user sees /dev/ as one
116 # of the alternatives. Later on the rule above will
117 # take care of showing device files in /dev/.
118 mapfile -t field_vals < <(journalctl -F "_EXE" 2>/dev/null; echo '/dev/')
119 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur}") )
120 if [[ "${COMPREPLY[@]}" = '/dev/' ]]; then
122 COMPREPLY=( $(compgen -f -- "${cur}") )
124 elif [[ $prev = '=' ]]; then
125 mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
126 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") )
129 COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
133 complete -F _journalctl journalctl