journalctl revision f11880744c27209a42f502c690db86b38d2db14b
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# journalctl(1) completion -*- shell-script -*-
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# This file is part of systemd.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# Copyright 2010 Ran Benita
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# 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# 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__contains_word () {
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner local w word=$1; shift
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner for w in "$@"; do
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner [[ $w = "$word" ]] && return
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
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl _AUDIT_{SESSION,LOGINUID}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
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_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
f11880744c27209a42f502c690db86b38d2db14bZbigniew Jędrzejewski-Szmek --version --list-catalog --update-catalog --list-boots'
a331b5e6d4724365bad9edeb9420c7e26e7f50daJan Janssen [ARG]='-b --boot --this-boot -D --directory -F --field
a331b5e6d4724365bad9edeb9420c7e26e7f50daJan Janssen -o --output -u --unit --user-unit'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [ARGUNKNOWN]='-c --cursor --interval -n --lines -p --priority --since --until
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --verify-key'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl case $prev in
a331b5e6d4724365bad9edeb9420c7e26e7f50daJan Janssen --boot|--this-boot|-b)
a331b5e6d4724365bad9edeb9420c7e26e7f50daJan Janssen comps=$(journalctl -F '_BOOT_ID' 2>/dev/null)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --directory|-D)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(compgen -d -- "$cur")
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl compopt -o filenames
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps='short short-monotonic verbose export json cat'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=${__journal_fields[*]}
1535fb73799f1c6079e8329af5d710bf9d55cbafHarald Hoyer comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null)
1535fb73799f1c6079e8329af5d710bf9d55cbafHarald Hoyer comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ $cur = -* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
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 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 compopt -o nospace
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Bieblcomplete -F _journalctl journalctl