journalctl revision d611dadcc74db10ba533ee6859308f5fc505aee1
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 () {
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local word=$1; shift
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl for w in $*; do [[ $w = $word ]] && return 0; done
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=(
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [STANDALONE]='-a --all --full
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl -b --this-boot --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
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --version --list-catalog --update-catalog'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [ARG]='-D --directory -F --field -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
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[*]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(journalctl -F '_SYSTEMD_UNIT')
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=$(journalctl -F '_SYSTEMD_USER_UNIT')
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