]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/zsh/_journalctl
43bec9b1d62cebd976c1ef774e883b40de5dd7af
[thirdparty/systemd.git] / shell-completion / zsh / _journalctl
1 #compdef journalctl -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
3
4 (( $+functions[_journalctl_fields] )) ||
5 _journalctl_fields() {
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}
12 _SYSTEMD_USER_UNIT USER_UNIT
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)
18 case $_jrnl_none in
19 yes) _values -s '=' 'possible fields' \
20 "${journal_fields[@]}:value:_journalctl_field_values ${words[CURRENT]%%=*}" ;;
21 *) _describe 'possible fields' journal_fields ;;
22 esac
23 }
24
25 (( $+functions[_journalctl_none] )) ||
26 _journalctl_none() {
27 local -a _commands _files _jrnl_none
28 # Setting use-cache will slow this down considerably
29 _commands=( ${"$(_call_program commands "$service $_sys_service_mgr -F _EXE" 2>/dev/null)"} )
30 _jrnl_none='yes'
31 _alternative : \
32 'files:/dev files:_files -W /dev -P /dev/' \
33 "commands:commands:($_commands[@])" \
34 'fields:fields:_journalctl_fields'
35 }
36
37 (( $+functions[_journalctl_field_values] )) ||
38 _journalctl_field_values() {
39 local -a _fields cmd
40 cmd=("journalctl $_sys_service_mgr" "-F ${@[-1]}" "2>/dev/null" )
41 _fields=$(_call_program fields $cmd[@])
42 _fields=${_fields//'\'/'\\'}
43 _fields=${_fields//':'/'\:'}
44 _fields=( ${(f)_fields} )
45 typeset -U _fields
46 _describe 'possible values' _fields
47 }
48
49 (( $+functions[_journalctl_boots] )) ||
50 _journalctl_boots() {
51 local -a _bootid _previousboots
52 _bootid=( ${(f)"$(_call_program bootid "$service -F _BOOT_ID")"} )
53 _previousboots=( -{1..${#_bootid}} )
54 _alternative : \
55 "offsets:boot offsets:compadd -a '_previousboots[1,-2]'" \
56 "bootid:boot ids:compadd -a _bootid"
57 }
58
59 # Build arguments for "journalctl" to be used in completion.
60 # Use both --user and --system modes, they are not exclusive.
61 local -a _modes; _modes=(--user --system)
62 local -a _modes_with_arg; _modes_with_arg=(--directory -D --file -M --machine --root)
63 typeset -a _sys_service_mgr
64 local w k v i=0 n=$#words
65 while (( i++ < n )); do
66 w=$words[$i]
67 if (( $_modes[(I)$w] )); then
68 _sys_service_mgr+=($w)
69 else
70 # Handle options with arguments. "--key=value" and "--key value".
71 k=${w%%=*}
72 if (( ${_modes_with_arg[(I)$k]} )); then
73 v=${w#*=}
74 if [[ "$k" != "$w" ]]; then
75 # "--key=value" style.
76 _sys_service_mgr+=($w)
77 else
78 # "--key value" style.
79 _sys_service_mgr+=($w ${words[((++i))]})
80 fi
81 fi
82 fi
83 done
84 _arguments -s \
85 {-h,--help}'[Show this help]' \
86 '--version[Show package version]' \
87 '--no-pager[Do not pipe output into a pager]' \
88 --no-hostname"[Don't show the hostname of local log messages]" \
89 {-l,--full}'[Show long fields in full]' \
90 {-a,--all}'[Show all fields, including long and unprintable]' \
91 {-f,--follow}'[Follow journal]' \
92 {-e,--pager-end}'[Jump to the end of the journal in the pager]' \
93 {-n+,--lines=}'[Number of journal entries to show]:integer' \
94 '--no-tail[Show all lines, even in follow mode]' \
95 {-r,--reverse}'[Reverse output]' \
96 {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
97 {-x,--catalog}'[Show explanatory texts with each log line]' \
98 {-q,--quiet}"[Don't show privilege warning]" \
99 {-m,--merge}'[Show entries from all available journals]' \
100 {-b+,--boot=}'[Show data only from the specified boot or offset]::boot id or offset:_journalctl_boots' \
101 '--list-boots[List boots ordered by time]' \
102 {-k,--dmesg}'[Show only kernel messages from the current boot]' \
103 {-u+,--unit=}'[Show data only from the specified unit]:units:_journalctl_field_values _SYSTEMD_UNIT' \
104 '--user-unit=[Show data only from the specified user session unit]:units:_journalctl_field_values USER_UNIT' \
105 {-p+,--priority=}'[Show only messages within the specified priority range]:priority:_journalctl_field_values PRIORITY' \
106 {-t+,--identifier=}'[Show only messages with the specified syslog identifier]:identifier:_journalctl_field_values SYSLOG_IDENTIFIER' \
107 {-c+,--cursor=}'[Start showing entries from the specified cursor]:cursors:_journalctl_field_values __CURSORS' \
108 '--cursor-file=[Show entries using cursor store in file]:file:_files' \
109 '--after-cursor=[Start showing entries from after the specified cursor]:cursors:_journalctl_field_values __CURSORS' \
110 '--since=[Start showing entries on or newer than the specified date]:YYYY-MM-DD HH\:MM\:SS' \
111 '--until=[Stop showing entries on or older than the specified date]:YYYY-MM-DD HH\:MM\:SS' \
112 {-F,--field=}'[List all values a certain field takes]:Fields:_journalctl_fields' \
113 '--system[Show system and kernel messages]' \
114 '--user[Show messages from user services]' \
115 '(--directory -D -M --machine --root --file)'{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
116 '(--directory -D -M --machine --root --file)'{-D+,--directory=}'[Show journal files from directory]:directories:_directories' \
117 '(--directory -D -M --machine --root --file)--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \
118 '(--directory -D -M --machine --root)*--file=[Operate on specified journal files]:file:_files' \
119 '--disk-usage[Show total disk usage]' \
120 '--dump-catalog[Dump messages in catalog]' \
121 '--flush[Flush all journal data from /run into /var]' \
122 '--force[Force recreation of the FSS keys]' \
123 '--header[Show journal header information]' \
124 '--interval=[Time interval for changing the FSS sealing key]:time interval' \
125 '--list-catalog[List messages in catalog]' \
126 '--new-id128[Generate a new 128 Bit ID]' \
127 '--rotate[Request immediate rotation of the journal files]' \
128 '--setup-keys[Generate a new FSS key pair]' \
129 '--sync[Synchronize unwritten journal messages to disk]' \
130 '--update-catalog[Update binary catalog database]' \
131 '--vacuum-files=[Leave only the specified number of journal files]:integer' \
132 '--vacuum-size=[Reduce disk usage below specified size]:bytes' \
133 '--vacuum-time=[Remove journal files older than specified time]:time' \
134 '--verify-key=[Specify FSS verification key]:FSS key' \
135 '--verify[Verify journal file consistency]' \
136 '*::default: _journalctl_none'