d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# journalctl(1) completion -*- shell-script -*-
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# This file is part of systemd.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# Copyright 2010 Ran Benita
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# systemd is free software; you can redistribute it and/or modify it
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# under the terms of the GNU Lesser General Public License as published by
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# the Free Software Foundation; either version 2.1 of the License, or
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# (at your option) any later version.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# systemd is distributed in the hope that it will be useful, but
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# WITHOUT ANY WARRANTY; without even the implied warranty of
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# General Public License for more details.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# You should have received a copy of the GNU Lesser General Public License
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# along with systemd; If not, see <http://www.gnu.org/licenses/>.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__contains_word () {
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner local w word=$1; shift
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner for w in "$@"; do
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner [[ $w = "$word" ]] && return
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner done
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh__get_machines() {
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh local a b
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh (machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh { while read a b; do echo " $a"; done; } | sort -u;
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh}
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl _{P,U,G}ID _COMM _EXE _CMDLINE
023dd03a4299f3ee0889d2f8dab45ab18e2f27f0Evgeny Vereshchagin _CAP_EFFECTIVE _AUDIT_{SESSION,LOGINUID}
023dd03a4299f3ee0889d2f8dab45ab18e2f27f0Evgeny Vereshchagin _SYSTEMD_{CGROUP,SESSION,{,USER_}UNIT,OWNER_UID,SLICE}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl _KERNEL_{DEVICE,SUBSYSTEM}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl _UDEV_{SYSNAME,DEVNODE,DEVLINK}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
be8f4a9fa732d61e845e1ab1a62ac3a6b368d3a7Zbigniew Jędrzejewski-Szmek__syslog_priorities=(emerg alert crit err warning notice info debug)
be8f4a9fa732d61e845e1ab1a62ac3a6b368d3a7Zbigniew Jędrzejewski-Szmek
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl_journalctl() {
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local -A OPTS=(
a331b5e6d4724365bad9edeb9420c7e26e7f50daJan Janssen [STANDALONE]='-a --all --full --system --user
a331b5e6d4724365bad9edeb9420c7e26e7f50daJan Janssen --disk-usage -f --follow --header
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl -h --help -l --local --new-id128 -m --merge --no-pager
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --no-tail -q --quiet --setup-keys --this-boot --verify
b4f91f2ba354c16dc23111cc231010c975c717a2Carlos Morata Castillo --version --list-catalog --update-catalog --list-boots
b4f91f2ba354c16dc23111cc231010c975c717a2Carlos Morata Castillo --show-cursor --dmesg -k --pager-end -e -r --reverse
b4f91f2ba354c16dc23111cc231010c975c717a2Carlos Morata Castillo --utc -x --catalog --no-full --force --dump-catalog
1a51b1b1c274c8b8047f9296e4bacbd89f3f9c14Marcos Mello --flush --rotate --sync'
b68b76897aca23f613afdc39a760992c711a7671Lennart Poettering [ARG]='-b --boot --this-boot -D --directory --file -F --field
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh -M --machine -o --output -u --unit --user-unit -p --priority
6409d3af08f0ce42acbfd7e7978a9bbb3312511eEvgeny Vereshchagin --vacuum-size --vacuum-time'
23c35c82c43cfb0997ef6dedfd39d5acac44e7d7Marcos Mello [ARGUNKNOWN]='-c --cursor --interval -n --lines -S --since -U --until
6409d3af08f0ce42acbfd7e7978a9bbb3312511eEvgeny Vereshchagin --after-cursor --verify-key -t --identifier
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh --root'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl case $prev in
b68b76897aca23f613afdc39a760992c711a7671Lennart Poettering --boot|--this-boot|-b)
a331b5e6d4724365bad9edeb9420c7e26e7f50daJan Janssen comps=$(journalctl -F '_BOOT_ID' 2>/dev/null)
a331b5e6d4724365bad9edeb9420c7e26e7f50daJan Janssen ;;
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --directory|-D)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(compgen -d -- "$cur")
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl compopt -o filenames
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ;;
7524c3cf4485bb9afd4ef0bf005a89f0319c19cdZbigniew Jędrzejewski-Szmek --file)
7524c3cf4485bb9afd4ef0bf005a89f0319c19cdZbigniew Jędrzejewski-Szmek comps=$(compgen -f -- "$cur")
7524c3cf4485bb9afd4ef0bf005a89f0319c19cdZbigniew Jędrzejewski-Szmek compopt -o filenames
7524c3cf4485bb9afd4ef0bf005a89f0319c19cdZbigniew Jędrzejewski-Szmek ;;
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --output|-o)
e4e5a85f34db9b18a5ae84a659fcdaf7e494dec1Ronny Chevalier comps='short short-iso short-precise short-monotonic verbose export json json-pretty json-sse cat'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ;;
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --field|-F)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=${__journal_fields[*]}
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh ;;
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh --machine|-M)
2720e0c0f006f9951550648b68f74d6772426f39Daniel J Walsh comps=$( __get_machines )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ;;
be8f4a9fa732d61e845e1ab1a62ac3a6b368d3a7Zbigniew Jędrzejewski-Szmek --priority|-p)
be8f4a9fa732d61e845e1ab1a62ac3a6b368d3a7Zbigniew Jędrzejewski-Szmek comps=${__syslog_priorities[*]}
be8f4a9fa732d61e845e1ab1a62ac3a6b368d3a7Zbigniew Jędrzejewski-Szmek ;;
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --unit|-u)
1535fb73799f1c6079e8329af5d710bf9d55cbafHarald Hoyer comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ;;
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --user-unit)
1535fb73799f1c6079e8329af5d710bf9d55cbafHarald Hoyer comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ;;
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl *)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl return 0
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl ;;
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl esac
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl return 0
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ $cur = -* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl return 0
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif [[ $cur = *=* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl mapfile -t field_vals < <(journalctl -F "${prev%=}" 2>/dev/null)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif [[ $cur = /dev* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl compopt -o filenames
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -f -- "${cur}") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif [[ $cur = /* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl # Append /dev/ to the list of completions, so that
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl # after typing /<TAB><TAB> the user sees /dev/ as one
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl # of the alternatives. Later on the rule above will
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl # take care of showing device files in /dev/.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl mapfile -t field_vals < <(journalctl -F "_EXE" 2>/dev/null; echo '/dev/')
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur}") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ "${COMPREPLY[@]}" = '/dev/' ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl compopt -o filenames
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -f -- "${cur}") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif [[ $prev = '=' ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl else
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl compopt -o nospace
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Bieblcomplete -F _journalctl journalctl