]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/journalctl
bash-completion: don't sort syslog priorities
[thirdparty/systemd.git] / shell-completion / bash / journalctl
CommitLineData
d611dadc 1# journalctl(1) completion -*- shell-script -*-
7059062c 2# SPDX-License-Identifier: LGPL-2.1+
d611dadc
MB
3#
4# This file is part of systemd.
5#
96b2fb93 6# Copyright © 2010 Ran Benita
d611dadc
MB
7#
8# systemd is free software; you can redistribute it and/or modify it
9# under the terms of the GNU Lesser General Public License as published by
10# the Free Software Foundation; either version 2.1 of the License, or
11# (at your option) any later version.
12#
13# systemd is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public License
19# along with systemd; If not, see <http://www.gnu.org/licenses/>.
20
21__contains_word () {
843cfcb1
ZJS
22 local w word=$1; shift
23 for w in "$@"; do
24 [[ $w = "$word" ]] && return
25 done
d611dadc
MB
26}
27
2720e0c0 28__get_machines() {
843cfcb1
ZJS
29 local a b
30 (machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \
31 { while read a b; do echo " $a"; done; } | sort -u;
2720e0c0
DW
32}
33
be8f4a9f
ZJS
34__syslog_priorities=(emerg alert crit err warning notice info debug)
35
d611dadc 36_journalctl() {
843cfcb1
ZJS
37 local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
38 local -A OPTS=(
39 [STANDALONE]='-a --all --full --system --user
40 --disk-usage -f --follow --header
41 -h --help -l --local -m --merge --no-pager
42 --no-tail -q --quiet --setup-keys --verify
43 --version --list-catalog --update-catalog --list-boots
44 --show-cursor --dmesg -k --pager-end -e -r --reverse
45 --utc -x --catalog --no-full --force --dump-catalog
46 --flush --rotate --sync --no-hostname -N --fields'
47 [ARG]='-b --boot -D --directory --file -F --field -t --identifier
48 -M --machine -o --output -u --unit --user-unit -p --priority
49 --root --case-sensitive'
50 [ARGUNKNOWN]='-c --cursor --interval -n --lines -S --since -U --until
51 --after-cursor --cursor-file --verify-key -g --grep
52 --vacuum-size --vacuum-time --vacuum-files --output-fields'
53 )
d611dadc 54
843cfcb1
ZJS
55 # Use the default completion for shell redirect operators
56 if __contains_word "$prev" '>' '>>' '&>'; then
57 compopt -o filenames
58 COMPREPLY=( $(compgen -f -- "$cur") )
59 return 0;
60 fi
1413763e 61
843cfcb1
ZJS
62 if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
63 case $prev in
64 --boot|-b)
65 comps=$(journalctl -F '_BOOT_ID' 2>/dev/null)
66 ;;
67 --directory|-D|--root)
68 comps=$(compgen -d -- "$cur")
69 compopt -o filenames
70 ;;
71 --file)
72 comps=$(compgen -f -- "$cur")
73 compopt -o filenames
74 ;;
75 --output|-o)
76 comps=$( journalctl --output=help 2>/dev/null )
77 ;;
78 --field|-F)
79 comps=$(journalctl --fields | sort 2>/dev/null)
80 ;;
81 --machine|-M)
82 comps=$( __get_machines )
83 ;;
84 --priority|-p)
85 comps=${__syslog_priorities[*]}
f8f54248 86 compopt -o nosort
843cfcb1
ZJS
87 ;;
88 --unit|-u)
89 comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null)
72c9177d 90 compopt -o filenames
843cfcb1
ZJS
91 ;;
92 --user-unit)
93 comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
94 ;;
95 --identifier|-t)
96 comps=$(journalctl -F 'SYSLOG_IDENTIFIER' 2>/dev/null)
97 ;;
98 --case-sensitive)
99 comps='yes no'
100 ;;
101 *)
d611dadc 102 return 0
843cfcb1
ZJS
103 ;;
104 esac
72c9177d 105 COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
843cfcb1
ZJS
106 return 0
107 fi
d611dadc 108
843cfcb1
ZJS
109 if [[ $cur = -* ]]; then
110 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
111 return 0
112 elif [[ $cur = *=* ]]; then
113 mapfile -t field_vals < <(journalctl -F "${prev%=}" 2>/dev/null)
114 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") )
115 elif [[ $cur = /dev* ]]; then
116 compopt -o filenames
117 COMPREPLY=( $(compgen -f -- "${cur}") )
118 elif [[ $cur = /* ]]; then
119 # Append /dev/ to the list of completions, so that
120 # after typing /<TAB><TAB> the user sees /dev/ as one
121 # of the alternatives. Later on the rule above will
122 # take care of showing device files in /dev/.
123 mapfile -t field_vals < <(journalctl -F "_EXE" 2>/dev/null; echo '/dev/')
124 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur}") )
125 if [[ "${COMPREPLY[@]}" = '/dev/' ]]; then
126 compopt -o filenames
127 COMPREPLY=( $(compgen -f -- "${cur}") )
d611dadc 128 fi
843cfcb1
ZJS
129 elif [[ $prev = '=' ]]; then
130 mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
131 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") )
132 else
133 mapfile -t field_vals < <(journalctl --fields 2>/dev/null)
134 compopt -o nospace
135 COMPREPLY=( $(compgen -W '${field_vals[*]}' -S= -- "$cur") )
136 fi
d611dadc
MB
137}
138
139complete -F _journalctl journalctl