]>
Commit | Line | Data |
---|---|---|
d611dadc MB |
1 | # journalctl(1) completion -*- shell-script -*- |
2 | # | |
3 | # This file is part of systemd. | |
4 | # | |
5 | # Copyright 2010 Ran Benita | |
6 | # | |
7 | # systemd is free software; you can redistribute it and/or modify it | |
8 | # under the terms of the GNU Lesser General Public License as published by | |
9 | # the Free Software Foundation; either version 2.1 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # systemd is distributed in the hope that it will be useful, but | |
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | # General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU Lesser General Public License | |
18 | # along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | __contains_word () { | |
a72d698d DR |
21 | local w word=$1; shift |
22 | for w in "$@"; do | |
23 | [[ $w = "$word" ]] && return | |
24 | done | |
d611dadc MB |
25 | } |
26 | ||
2720e0c0 DW |
27 | __get_machines() { |
28 | local a b | |
29 | (machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; echo ".host") | \ | |
30 | { while read a b; do echo " $a"; done; } | sort -u; | |
31 | } | |
32 | ||
d611dadc MB |
33 | __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} |
34 | ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE | |
35 | _{P,U,G}ID _COMM _EXE _CMDLINE | |
023dd03a EV |
36 | _CAP_EFFECTIVE _AUDIT_{SESSION,LOGINUID} |
37 | _SYSTEMD_{CGROUP,SESSION,{,USER_}UNIT,OWNER_UID,SLICE} | |
d611dadc MB |
38 | _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP |
39 | _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT | |
40 | _KERNEL_{DEVICE,SUBSYSTEM} | |
41 | _UDEV_{SYSNAME,DEVNODE,DEVLINK} | |
42 | __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP) | |
43 | ||
be8f4a9f ZJS |
44 | __syslog_priorities=(emerg alert crit err warning notice info debug) |
45 | ||
d611dadc MB |
46 | _journalctl() { |
47 | local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
48 | local -A OPTS=( | |
a331b5e6 JJ |
49 | [STANDALONE]='-a --all --full --system --user |
50 | --disk-usage -f --follow --header | |
d611dadc MB |
51 | -h --help -l --local --new-id128 -m --merge --no-pager |
52 | --no-tail -q --quiet --setup-keys --this-boot --verify | |
b4f91f2b CMC |
53 | --version --list-catalog --update-catalog --list-boots |
54 | --show-cursor --dmesg -k --pager-end -e -r --reverse | |
55 | --utc -x --catalog --no-full --force --dump-catalog | |
1a51b1b1 | 56 | --flush --rotate --sync' |
b68b7689 | 57 | [ARG]='-b --boot --this-boot -D --directory --file -F --field |
2720e0c0 | 58 | -M --machine -o --output -u --unit --user-unit -p --priority |
6409d3af | 59 | --vacuum-size --vacuum-time' |
23c35c82 | 60 | [ARGUNKNOWN]='-c --cursor --interval -n --lines -S --since -U --until |
6409d3af | 61 | --after-cursor --verify-key -t --identifier |
2720e0c0 | 62 | --root' |
d611dadc MB |
63 | ) |
64 | ||
65 | if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then | |
66 | case $prev in | |
b68b7689 | 67 | --boot|--this-boot|-b) |
a331b5e6 JJ |
68 | comps=$(journalctl -F '_BOOT_ID' 2>/dev/null) |
69 | ;; | |
d611dadc MB |
70 | --directory|-D) |
71 | comps=$(compgen -d -- "$cur") | |
72 | compopt -o filenames | |
73 | ;; | |
7524c3cf ZJS |
74 | --file) |
75 | comps=$(compgen -f -- "$cur") | |
76 | compopt -o filenames | |
77 | ;; | |
d611dadc | 78 | --output|-o) |
e4e5a85f | 79 | comps='short short-iso short-precise short-monotonic verbose export json json-pretty json-sse cat' |
d611dadc MB |
80 | ;; |
81 | --field|-F) | |
82 | comps=${__journal_fields[*]} | |
2720e0c0 DW |
83 | ;; |
84 | --machine|-M) | |
85 | comps=$( __get_machines ) | |
d611dadc | 86 | ;; |
be8f4a9f ZJS |
87 | --priority|-p) |
88 | comps=${__syslog_priorities[*]} | |
89 | ;; | |
d611dadc | 90 | --unit|-u) |
1535fb73 | 91 | comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null) |
d611dadc MB |
92 | ;; |
93 | --user-unit) | |
1535fb73 | 94 | comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null) |
d611dadc MB |
95 | ;; |
96 | *) | |
97 | return 0 | |
98 | ;; | |
99 | esac | |
100 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
101 | return 0 | |
102 | fi | |
103 | ||
104 | if [[ $cur = -* ]]; then | |
105 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
106 | return 0 | |
107 | elif [[ $cur = *=* ]]; then | |
108 | mapfile -t field_vals < <(journalctl -F "${prev%=}" 2>/dev/null) | |
109 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") ) | |
110 | elif [[ $cur = /dev* ]]; then | |
111 | compopt -o filenames | |
112 | COMPREPLY=( $(compgen -f -- "${cur}") ) | |
113 | elif [[ $cur = /* ]]; then | |
114 | # Append /dev/ to the list of completions, so that | |
115 | # after typing /<TAB><TAB> the user sees /dev/ as one | |
116 | # of the alternatives. Later on the rule above will | |
117 | # take care of showing device files in /dev/. | |
118 | mapfile -t field_vals < <(journalctl -F "_EXE" 2>/dev/null; echo '/dev/') | |
119 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur}") ) | |
120 | if [[ "${COMPREPLY[@]}" = '/dev/' ]]; then | |
121 | compopt -o filenames | |
122 | COMPREPLY=( $(compgen -f -- "${cur}") ) | |
123 | fi | |
124 | elif [[ $prev = '=' ]]; then | |
125 | mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null) | |
126 | COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") ) | |
127 | else | |
128 | compopt -o nospace | |
129 | COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") ) | |
130 | fi | |
131 | } | |
132 | ||
133 | complete -F _journalctl journalctl |