]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/zsh/_journalctl
zsh/_journalctl: complete -g, --case-sensitive, 'help' (pseudo-)facility
[thirdparty/systemd.git] / shell-completion / zsh / _journalctl
CommitLineData
682e043c 1#compdef journalctl
db9ecf05 2# SPDX-License-Identifier: LGPL-2.1-or-later
7e83c0e0 3
c501ecd7 4(( $+functions[_journalctl_fields] )) ||
5_journalctl_fields() {
7e83c0e0
WG
6 local -a journal_fields
7 journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
8 ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID}
9 _{P,U,G}ID _COMM _EXE _CMDLINE
10 _AUDIT_{SESSION,LOGINUID}
11 _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
9e15a18a 12 _SYSTEMD_USER_UNIT USER_UNIT
7e83c0e0
WG
13 _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
14 _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
15 _KERNEL_{DEVICE,SUBSYSTEM}
16 _UDEV_{SYSNAME,DEVNODE,DEVLINK}
17 __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
ca080637
WG
18 case $_jrnl_none in
19 yes) _values -s '=' 'possible fields' \
c501ecd7 20 "${journal_fields[@]}:value:_journalctl_field_values ${words[CURRENT]%%=*}" ;;
ca080637
WG
21 *) _describe 'possible fields' journal_fields ;;
22 esac
7e83c0e0
WG
23}
24
c501ecd7 25(( $+functions[_journalctl_none] )) ||
26_journalctl_none() {
ca080637 27 local -a _commands _files _jrnl_none
4af6e458 28 # Setting use-cache will slow this down considerably
45b156c1 29 _commands=( ${(f)"$(_call_program commands "$service $_sys_service_mgr -F _EXE" 2>/dev/null)"} )
ca080637 30 _jrnl_none='yes'
7e83c0e0
WG
31 _alternative : \
32 'files:/dev files:_files -W /dev -P /dev/' \
45b156c1 33 'commands:commands:compadd -a _commands' \
c501ecd7 34 'fields:fields:_journalctl_fields'
7e83c0e0
WG
35}
36
c501ecd7 37(( $+functions[_journalctl_field_values] )) ||
38_journalctl_field_values() {
7e83c0e0 39 local -a _fields cmd
d551b8fc 40 cmd=("journalctl $_sys_service_mgr" "-F ${@[-1]}" "2>/dev/null" )
655fd9d7
DC
41 _fields=$(_call_program fields $cmd[@])
42 _fields=${_fields//'\'/'\\'}
43 _fields=${_fields//':'/'\:'}
44 _fields=( ${(f)_fields} )
7e83c0e0
WG
45 typeset -U _fields
46 _describe 'possible values' _fields
47}
48
c501ecd7 49(( $+functions[_journalctl_boots] )) ||
50_journalctl_boots() {
4a8fa990 51 local -a _bootid _previousboots
c2026f28 52 _bootid=( ${(f)"$(_call_program bootid "$service -F _BOOT_ID")"} )
4a8fa990
WG
53 _previousboots=( -{1..${#_bootid}} )
54 _alternative : \
c2026f28
EC
55 "offsets:boot offsets:compadd -a '_previousboots[1,-2]'" \
56 "bootid:boot ids:compadd -a _bootid"
4a8fa990
WG
57}
58
989db9b3
ZJS
59(( $+functions[_journalctl_facilities] )) ||
60_journalctl_facilities() {
61 local -a _journalctl_facilities
da9e1f83 62 _journalctl_facilities=(help kern user mail daemon auth syslog lpr news uucp cron authpriv ftp local0 local1 local2 local3 local4 local5 local6 local7)
989db9b3
ZJS
63 _describe 'possible values' _journalctl_facilities
64}
65
178c8c24
FS
66(( $+functions[_journalctl_namespaces] )) ||
67_journalctl_namespaces() {
68 local -a _journalctl_namespaces
69 _journalctl_namespaces=( ${(f)"$(_call_program namespaces "$service --list-namespaces --output=cat" 2>/dev/null)"} )
70 _describe 'possible values' _journalctl_namespaces
71}
72
d551b8fc
DH
73# Build arguments for "journalctl" to be used in completion.
74# Use both --user and --system modes, they are not exclusive.
75local -a _modes; _modes=(--user --system)
b2fe35fe 76local -a _modes_with_arg; _modes_with_arg=(--directory -D --file -M --machine --root)
d551b8fc 77typeset -a _sys_service_mgr
b2fe35fe 78local w k v i=0 n=$#words
d551b8fc
DH
79while (( i++ < n )); do
80 w=$words[$i]
81 if (( $_modes[(I)$w] )); then
82 _sys_service_mgr+=($w)
83 else
b2fe35fe
DH
84 # Handle options with arguments. "--key=value" and "--key value".
85 k=${w%%=*}
86 if (( ${_modes_with_arg[(I)$k]} )); then
87 v=${w#*=}
88 if [[ "$k" != "$w" ]]; then
89 # "--key=value" style.
90 _sys_service_mgr+=($w)
91 else
92 # "--key value" style.
93 _sys_service_mgr+=($w ${words[((++i))]})
94 fi
d551b8fc
DH
95 fi
96 fi
97done
7e83c0e0
WG
98_arguments -s \
99 {-h,--help}'[Show this help]' \
100 '--version[Show package version]' \
101 '--no-pager[Do not pipe output into a pager]' \
a5057365 102 --no-hostname"[Don't show the hostname of local log messages]" \
7e83c0e0
WG
103 {-l,--full}'[Show long fields in full]' \
104 {-a,--all}'[Show all fields, including long and unprintable]' \
105 {-f,--follow}'[Follow journal]' \
106 {-e,--pager-end}'[Jump to the end of the journal in the pager]' \
862f4963 107 {-n+,--lines=}'[Number of journal entries to show]:integer' \
7e83c0e0
WG
108 '--no-tail[Show all lines, even in follow mode]' \
109 {-r,--reverse}'[Reverse output]' \
a02c5fe7 110 {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
7e83c0e0
WG
111 {-x,--catalog}'[Show explanatory texts with each log line]' \
112 {-q,--quiet}"[Don't show privilege warning]" \
113 {-m,--merge}'[Show entries from all available journals]' \
c501ecd7 114 {-b+,--boot=}'[Show data only from the specified boot or offset]::boot id or offset:_journalctl_boots' \
f1188074 115 '--list-boots[List boots ordered by time]' \
c736283b 116 {-k,--dmesg}'[Show only kernel messages from the current boot]' \
c501ecd7 117 {-u+,--unit=}'[Show data only from the specified unit]:units:_journalctl_field_values _SYSTEMD_UNIT' \
118 '--user-unit=[Show data only from the specified user session unit]:units:_journalctl_field_values USER_UNIT' \
119 {-p+,--priority=}'[Show only messages within the specified priority range]:priority:_journalctl_field_values PRIORITY' \
989db9b3
ZJS
120 '--facility=[Filter messages by facility]:facility:_journalctl_facilities' \
121 {-t+,--identifier=}'[Filter messages by syslog identifier]:identifier:_journalctl_field_values SYSLOG_IDENTIFIER' \
c501ecd7 122 {-c+,--cursor=}'[Start showing entries from the specified cursor]:cursors:_journalctl_field_values __CURSORS' \
d9e15cbd 123 '--cursor-file=[Show entries using cursor store in file]:file:_files' \
c501ecd7 124 '--after-cursor=[Start showing entries from after the specified cursor]:cursors:_journalctl_field_values __CURSORS' \
c736283b
JSJ
125 '--since=[Start showing entries on or newer than the specified date]:YYYY-MM-DD HH\:MM\:SS' \
126 '--until=[Stop showing entries on or older than the specified date]:YYYY-MM-DD HH\:MM\:SS' \
da9e1f83
ŠN
127 {-g+,--grep=}'[Show entries with MESSAGE field matching PCRE pattern]' \
128 '--case-sensitive=[Force case sensitive or insensitive matching]:boolean:(true false)' \
c501ecd7 129 {-F,--field=}'[List all values a certain field takes]:Fields:_journalctl_fields' \
7e83c0e0
WG
130 '--system[Show system and kernel messages]' \
131 '--user[Show messages from user services]' \
ba89f806
DH
132 '(--directory -D -M --machine --root --file)'{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
133 '(--directory -D -M --machine --root --file)'{-D+,--directory=}'[Show journal files from directory]:directories:_directories' \
64431774
EC
134 '(--directory -D -M --machine --root --file)--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \
135 '(--directory -D -M --machine --root)*--file=[Operate on specified journal files]:file:_files' \
7e83c0e0 136 '--disk-usage[Show total disk usage]' \
7e83c0e0 137 '--dump-catalog[Dump messages in catalog]' \
3005b380 138 '--flush[Flush all journal data from /run into /var]' \
c736283b 139 '--force[Force recreation of the FSS keys]' \
3005b380 140 '--header[Show journal header information]' \
7e83c0e0 141 '--interval=[Time interval for changing the FSS sealing key]:time interval' \
3005b380 142 '--list-catalog[List messages in catalog]' \
68f66a17 143 '--list-namespaces[List available journal namespaces]' \
178c8c24 144 '--namespace[Show journal data from specified namespace]:namespace:_journalctl_namespaces' \
3005b380
RP
145 '--new-id128[Generate a new 128 Bit ID]' \
146 '--rotate[Request immediate rotation of the journal files]' \
147 '--setup-keys[Generate a new FSS key pair]' \
148 '--sync[Synchronize unwritten journal messages to disk]' \
149 '--update-catalog[Update binary catalog database]' \
150 '--vacuum-files=[Leave only the specified number of journal files]:integer' \
151 '--vacuum-size=[Reduce disk usage below specified size]:bytes' \
152 '--vacuum-time=[Remove journal files older than specified time]:time' \
7e83c0e0 153 '--verify-key=[Specify FSS verification key]:FSS key' \
3005b380 154 '--verify[Verify journal file consistency]' \
c501ecd7 155 '*::default: _journalctl_none'