]>
Commit | Line | Data |
---|---|---|
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 | ||
d551b8fc DH |
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) | |
b2fe35fe | 62 | local -a _modes_with_arg; _modes_with_arg=(--directory -D --file -M --machine --root) |
d551b8fc | 63 | typeset -a _sys_service_mgr |
b2fe35fe | 64 | local w k v i=0 n=$#words |
d551b8fc DH |
65 | while (( i++ < n )); do |
66 | w=$words[$i] | |
67 | if (( $_modes[(I)$w] )); then | |
68 | _sys_service_mgr+=($w) | |
69 | else | |
b2fe35fe DH |
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 | |
d551b8fc DH |
81 | fi |
82 | fi | |
83 | done | |
7e83c0e0 WG |
84 | _arguments -s \ |
85 | {-h,--help}'[Show this help]' \ | |
86 | '--version[Show package version]' \ | |
87 | '--no-pager[Do not pipe output into a pager]' \ | |
a5057365 | 88 | --no-hostname"[Don't show the hostname of local log messages]" \ |
7e83c0e0 WG |
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]' \ | |
862f4963 | 93 | {-n+,--lines=}'[Number of journal entries to show]:integer' \ |
7e83c0e0 WG |
94 | '--no-tail[Show all lines, even in follow mode]' \ |
95 | {-r,--reverse}'[Reverse output]' \ | |
a02c5fe7 | 96 | {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \ |
7e83c0e0 WG |
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]' \ | |
c501ecd7 | 100 | {-b+,--boot=}'[Show data only from the specified boot or offset]::boot id or offset:_journalctl_boots' \ |
f1188074 | 101 | '--list-boots[List boots ordered by time]' \ |
c736283b | 102 | {-k,--dmesg}'[Show only kernel messages from the current boot]' \ |
c501ecd7 | 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' \ | |
d9e15cbd | 108 | '--cursor-file=[Show entries using cursor store in file]:file:_files' \ |
c501ecd7 | 109 | '--after-cursor=[Start showing entries from after the specified cursor]:cursors:_journalctl_field_values __CURSORS' \ |
c736283b JSJ |
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' \ | |
c501ecd7 | 112 | {-F,--field=}'[List all values a certain field takes]:Fields:_journalctl_fields' \ |
7e83c0e0 WG |
113 | '--system[Show system and kernel messages]' \ |
114 | '--user[Show messages from user services]' \ | |
ba89f806 DH |
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' \ | |
64431774 EC |
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' \ | |
7e83c0e0 | 119 | '--disk-usage[Show total disk usage]' \ |
7e83c0e0 | 120 | '--dump-catalog[Dump messages in catalog]' \ |
3005b380 | 121 | '--flush[Flush all journal data from /run into /var]' \ |
c736283b | 122 | '--force[Force recreation of the FSS keys]' \ |
3005b380 | 123 | '--header[Show journal header information]' \ |
7e83c0e0 | 124 | '--interval=[Time interval for changing the FSS sealing key]:time interval' \ |
3005b380 RP |
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' \ | |
7e83c0e0 | 134 | '--verify-key=[Specify FSS verification key]:FSS key' \ |
3005b380 | 135 | '--verify[Verify journal file consistency]' \ |
c501ecd7 | 136 | '*::default: _journalctl_none' |