]>
Commit | Line | Data |
---|---|---|
7e83c0e0 | 1 | #compdef journalctl |
7059062c | 2 | # SPDX-License-Identifier: LGPL-2.1+ |
7e83c0e0 | 3 | |
7e83c0e0 WG |
4 | _list_fields() { |
5 | local -a journal_fields | |
6 | journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC} | |
7 | ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} | |
8 | _{P,U,G}ID _COMM _EXE _CMDLINE | |
9 | _AUDIT_{SESSION,LOGINUID} | |
10 | _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID} | |
9e15a18a | 11 | _SYSTEMD_USER_UNIT USER_UNIT |
7e83c0e0 WG |
12 | _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP |
13 | _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT | |
14 | _KERNEL_{DEVICE,SUBSYSTEM} | |
15 | _UDEV_{SYSNAME,DEVNODE,DEVLINK} | |
16 | __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP) | |
ca080637 WG |
17 | case $_jrnl_none in |
18 | yes) _values -s '=' 'possible fields' \ | |
19 | "${journal_fields[@]}:value:_journal_fields ${words[CURRENT]%%=*}" ;; | |
20 | *) _describe 'possible fields' journal_fields ;; | |
21 | esac | |
7e83c0e0 WG |
22 | } |
23 | ||
24 | _journal_none() { | |
ca080637 | 25 | local -a _commands _files _jrnl_none |
4af6e458 | 26 | # Setting use-cache will slow this down considerably |
21d84318 | 27 | _commands=( ${"$(_call_program commands "$service $_sys_service_mgr -F _EXE" 2>/dev/null)"} ) |
ca080637 | 28 | _jrnl_none='yes' |
7e83c0e0 WG |
29 | _alternative : \ |
30 | 'files:/dev files:_files -W /dev -P /dev/' \ | |
31 | "commands:commands:($_commands[@])" \ | |
32 | 'fields:fields:_list_fields' | |
33 | } | |
34 | ||
35 | _journal_fields() { | |
36 | local -a _fields cmd | |
d551b8fc | 37 | cmd=("journalctl $_sys_service_mgr" "-F ${@[-1]}" "2>/dev/null" ) |
655fd9d7 DC |
38 | _fields=$(_call_program fields $cmd[@]) |
39 | _fields=${_fields//'\'/'\\'} | |
40 | _fields=${_fields//':'/'\:'} | |
41 | _fields=( ${(f)_fields} ) | |
7e83c0e0 WG |
42 | typeset -U _fields |
43 | _describe 'possible values' _fields | |
44 | } | |
45 | ||
4a8fa990 WG |
46 | _journal_boots() { |
47 | local -a _bootid _previousboots | |
c2026f28 | 48 | _bootid=( ${(f)"$(_call_program bootid "$service -F _BOOT_ID")"} ) |
4a8fa990 WG |
49 | _previousboots=( -{1..${#_bootid}} ) |
50 | _alternative : \ | |
c2026f28 EC |
51 | "offsets:boot offsets:compadd -a '_previousboots[1,-2]'" \ |
52 | "bootid:boot ids:compadd -a _bootid" | |
4a8fa990 WG |
53 | } |
54 | ||
d551b8fc DH |
55 | # Build arguments for "journalctl" to be used in completion. |
56 | # Use both --user and --system modes, they are not exclusive. | |
57 | local -a _modes; _modes=(--user --system) | |
b2fe35fe | 58 | local -a _modes_with_arg; _modes_with_arg=(--directory -D --file -M --machine --root) |
d551b8fc | 59 | typeset -a _sys_service_mgr |
b2fe35fe | 60 | local w k v i=0 n=$#words |
d551b8fc DH |
61 | while (( i++ < n )); do |
62 | w=$words[$i] | |
63 | if (( $_modes[(I)$w] )); then | |
64 | _sys_service_mgr+=($w) | |
65 | else | |
b2fe35fe DH |
66 | # Handle options with arguments. "--key=value" and "--key value". |
67 | k=${w%%=*} | |
68 | if (( ${_modes_with_arg[(I)$k]} )); then | |
69 | v=${w#*=} | |
70 | if [[ "$k" != "$w" ]]; then | |
71 | # "--key=value" style. | |
72 | _sys_service_mgr+=($w) | |
73 | else | |
74 | # "--key value" style. | |
75 | _sys_service_mgr+=($w ${words[((++i))]}) | |
76 | fi | |
d551b8fc DH |
77 | fi |
78 | fi | |
79 | done | |
7e83c0e0 WG |
80 | _arguments -s \ |
81 | {-h,--help}'[Show this help]' \ | |
82 | '--version[Show package version]' \ | |
83 | '--no-pager[Do not pipe output into a pager]' \ | |
84 | {-l,--full}'[Show long fields in full]' \ | |
85 | {-a,--all}'[Show all fields, including long and unprintable]' \ | |
86 | {-f,--follow}'[Follow journal]' \ | |
87 | {-e,--pager-end}'[Jump to the end of the journal in the pager]' \ | |
862f4963 | 88 | {-n+,--lines=}'[Number of journal entries to show]:integer' \ |
7e83c0e0 WG |
89 | '--no-tail[Show all lines, even in follow mode]' \ |
90 | {-r,--reverse}'[Reverse output]' \ | |
a02c5fe7 | 91 | {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \ |
7e83c0e0 WG |
92 | {-x,--catalog}'[Show explanatory texts with each log line]' \ |
93 | {-q,--quiet}"[Don't show privilege warning]" \ | |
94 | {-m,--merge}'[Show entries from all available journals]' \ | |
c2026f28 | 95 | {-b+,--boot=}'[Show data only from the specified boot or offset]::boot id or offset:_journal_boots' \ |
f1188074 | 96 | '--list-boots[List boots ordered by time]' \ |
c736283b | 97 | {-k,--dmesg}'[Show only kernel messages from the current boot]' \ |
862f4963 | 98 | {-u+,--unit=}'[Show data only from the specified unit]:units:_journal_fields _SYSTEMD_UNIT' \ |
9e15a18a | 99 | '--user-unit=[Show data only from the specified user session unit]:units:_journal_fields USER_UNIT' \ |
862f4963 | 100 | {-p+,--priority=}'[Show only messages within the specified priority range]:priority:_journal_fields PRIORITY' \ |
5ef80f3b | 101 | {-t+,--identifier=}'[Show only messages with the specified syslog identifier]:identifier:_journal_fields SYSLOG_IDENTIFIER' \ |
c736283b JSJ |
102 | {-c+,--cursor=}'[Start showing entries from the specified cursor]:cursors:_journal_fields __CURSORS' \ |
103 | '--after-cursor=[Start showing entries from after the specified cursor]:cursors:_journal_fields __CURSORS' \ | |
104 | '--since=[Start showing entries on or newer than the specified date]:YYYY-MM-DD HH\:MM\:SS' \ | |
105 | '--until=[Stop showing entries on or older than the specified date]:YYYY-MM-DD HH\:MM\:SS' \ | |
7e83c0e0 WG |
106 | {-F,--field=}'[List all values a certain field takes]:Fields:_list_fields' \ |
107 | '--system[Show system and kernel messages]' \ | |
108 | '--user[Show messages from user services]' \ | |
ba89f806 DH |
109 | '(--directory -D -M --machine --root --file)'{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \ |
110 | '(--directory -D -M --machine --root --file)'{-D+,--directory=}'[Show journal files from directory]:directories:_directories' \ | |
64431774 EC |
111 | '(--directory -D -M --machine --root --file)--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \ |
112 | '(--directory -D -M --machine --root)*--file=[Operate on specified journal files]:file:_files' \ | |
7e83c0e0 WG |
113 | '--new-id128[Generate a new 128 Bit ID]' \ |
114 | '--header[Show journal header information]' \ | |
115 | '--disk-usage[Show total disk usage]' \ | |
116 | '--list-catalog[List messages in catalog]' \ | |
117 | '--dump-catalog[Dump messages in catalog]' \ | |
118 | '--update-catalog[Update binary catalog database]' \ | |
c736283b JSJ |
119 | '--setup-keys[Generate a new FSS key pair]' \ |
120 | '--force[Force recreation of the FSS keys]' \ | |
7e83c0e0 WG |
121 | '--interval=[Time interval for changing the FSS sealing key]:time interval' \ |
122 | '--verify[Verify journal file consistency]' \ | |
123 | '--verify-key=[Specify FSS verification key]:FSS key' \ | |
124 | '*::default: _journal_none' |