]>
Commit | Line | Data |
---|---|---|
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 | # | |
6 | # Copyright 2010 Ran Benita | |
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 () { | |
a72d698d DR |
22 | local w word=$1; shift |
23 | for w in "$@"; do | |
24 | [[ $w = "$word" ]] && return | |
25 | done | |
d611dadc MB |
26 | } |
27 | ||
2720e0c0 DW |
28 | __get_machines() { |
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; | |
32 | } | |
33 | ||
be8f4a9f ZJS |
34 | __syslog_priorities=(emerg alert crit err warning notice info debug) |
35 | ||
d611dadc MB |
36 | _journalctl() { |
37 | local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
38 | local -A OPTS=( | |
a331b5e6 JJ |
39 | [STANDALONE]='-a --all --full --system --user |
40 | --disk-usage -f --follow --header | |
d611dadc | 41 | -h --help -l --local --new-id128 -m --merge --no-pager |
41053e9b | 42 | --no-tail -q --quiet --setup-keys --verify |
b4f91f2b CMC |
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 | |
41053e9b YW |
46 | --flush --rotate --sync --no-hostname -N --fields' |
47 | [ARG]='-b --boot -D --directory --file -F --field -t --identifier | |
2720e0c0 | 48 | -M --machine -o --output -u --unit --user-unit -p --priority |
2720e0c0 | 49 | --root' |
41053e9b YW |
50 | [ARGUNKNOWN]='-c --cursor --interval -n --lines -S --since -U --until |
51 | --after-cursor --verify-key | |
52 | --vacuum-size --vacuum-time --vacuum-files --output-fields' | |
d611dadc MB |
53 | ) |
54 | ||
55 | if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then | |
56 | case $prev in | |
41053e9b | 57 | --boot|-b) |
a331b5e6 JJ |
58 | comps=$(journalctl -F '_BOOT_ID' 2>/dev/null) |
59 | ;; | |
41053e9b | 60 | --directory|-D|--root) |
d611dadc MB |
61 | comps=$(compgen -d -- "$cur") |
62 | compopt -o filenames | |
63 | ;; | |
7524c3cf ZJS |
64 | --file) |
65 | comps=$(compgen -f -- "$cur") | |
66 | compopt -o filenames | |
67 | ;; | |
d611dadc | 68 | --output|-o) |
49805b3d | 69 | comps='short short-full short-iso short-iso-precise short-precise short-monotonic short-unix verbose export json json-pretty json-sse cat with-unit' |
d611dadc MB |
70 | ;; |
71 | --field|-F) | |
67044a24 | 72 | comps=$(journalctl --fields | sort 2>/dev/null) |
2720e0c0 DW |
73 | ;; |
74 | --machine|-M) | |
75 | comps=$( __get_machines ) | |
d611dadc | 76 | ;; |
be8f4a9f ZJS |
77 | --priority|-p) |
78 | comps=${__syslog_priorities[*]} | |
79 | ;; | |
d611dadc | 80 | --unit|-u) |
1535fb73 | 81 | comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null) |
d611dadc MB |
82 | ;; |
83 | --user-unit) | |
1535fb73 | 84 | comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null) |
d611dadc | 85 | ;; |
28b6b5de NK |
86 | --identifier|-t) |
87 | comps=$(journalctl -F 'SYSLOG_IDENTIFIER' 2>/dev/null) | |
88 | ;; | |
d611dadc MB |
89 | *) |
90 | return 0 | |
91 | ;; | |
92 | esac | |
93 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
94 | return 0 | |
95 | fi | |
96 | ||
97 | if [[ $cur = -* ]]; then | |
98 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
99 | return 0 | |
100 | elif [[ $cur = *=* ]]; then | |
101 | mapfile -t field_vals < <(journalctl -F "${prev%=}" 2>/dev/null) | |
102 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") ) | |
103 | elif [[ $cur = /dev* ]]; then | |
104 | compopt -o filenames | |
105 | COMPREPLY=( $(compgen -f -- "${cur}") ) | |
106 | elif [[ $cur = /* ]]; then | |
107 | # Append /dev/ to the list of completions, so that | |
108 | # after typing /<TAB><TAB> the user sees /dev/ as one | |
109 | # of the alternatives. Later on the rule above will | |
110 | # take care of showing device files in /dev/. | |
111 | mapfile -t field_vals < <(journalctl -F "_EXE" 2>/dev/null; echo '/dev/') | |
112 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur}") ) | |
113 | if [[ "${COMPREPLY[@]}" = '/dev/' ]]; then | |
114 | compopt -o filenames | |
115 | COMPREPLY=( $(compgen -f -- "${cur}") ) | |
116 | fi | |
117 | elif [[ $prev = '=' ]]; then | |
118 | mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null) | |
119 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") ) | |
120 | else | |
67044a24 | 121 | mapfile -t field_vals < <(journalctl --fields 2>/dev/null) |
d611dadc | 122 | compopt -o nospace |
67044a24 | 123 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -S= -- "$cur") ) |
d611dadc MB |
124 | fi |
125 | } | |
126 | ||
127 | complete -F _journalctl journalctl |