]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/zsh/_journalctl
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / shell-completion / zsh / _journalctl
CommitLineData
7e83c0e0 1#compdef journalctl
7059062c 2# SPDX-License-Identifier: LGPL-2.1+
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
21d84318 29 _commands=( ${"$(_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/' \
33 "commands:commands:($_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.
61local -a _modes; _modes=(--user --system)
b2fe35fe 62local -a _modes_with_arg; _modes_with_arg=(--directory -D --file -M --machine --root)
d551b8fc 63typeset -a _sys_service_mgr
b2fe35fe 64local w k v i=0 n=$#words
d551b8fc
DH
65while (( 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
83done
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]' \
88 {-l,--full}'[Show long fields in full]' \
89 {-a,--all}'[Show all fields, including long and unprintable]' \
90 {-f,--follow}'[Follow journal]' \
91 {-e,--pager-end}'[Jump to the end of the journal in the pager]' \
862f4963 92 {-n+,--lines=}'[Number of journal entries to show]:integer' \
7e83c0e0
WG
93 '--no-tail[Show all lines, even in follow mode]' \
94 {-r,--reverse}'[Reverse output]' \
a02c5fe7 95 {-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
7e83c0e0
WG
96 {-x,--catalog}'[Show explanatory texts with each log line]' \
97 {-q,--quiet}"[Don't show privilege warning]" \
98 {-m,--merge}'[Show entries from all available journals]' \
c501ecd7 99 {-b+,--boot=}'[Show data only from the specified boot or offset]::boot id or offset:_journalctl_boots' \
f1188074 100 '--list-boots[List boots ordered by time]' \
c736283b 101 {-k,--dmesg}'[Show only kernel messages from the current boot]' \
c501ecd7 102 {-u+,--unit=}'[Show data only from the specified unit]:units:_journalctl_field_values _SYSTEMD_UNIT' \
103 '--user-unit=[Show data only from the specified user session unit]:units:_journalctl_field_values USER_UNIT' \
104 {-p+,--priority=}'[Show only messages within the specified priority range]:priority:_journalctl_field_values PRIORITY' \
105 {-t+,--identifier=}'[Show only messages with the specified syslog identifier]:identifier:_journalctl_field_values SYSLOG_IDENTIFIER' \
106 {-c+,--cursor=}'[Start showing entries from the specified cursor]:cursors:_journalctl_field_values __CURSORS' \
107 '--after-cursor=[Start showing entries from after the specified cursor]:cursors:_journalctl_field_values __CURSORS' \
c736283b
JSJ
108 '--since=[Start showing entries on or newer than the specified date]:YYYY-MM-DD HH\:MM\:SS' \
109 '--until=[Stop showing entries on or older than the specified date]:YYYY-MM-DD HH\:MM\:SS' \
c501ecd7 110 {-F,--field=}'[List all values a certain field takes]:Fields:_journalctl_fields' \
7e83c0e0
WG
111 '--system[Show system and kernel messages]' \
112 '--user[Show messages from user services]' \
ba89f806
DH
113 '(--directory -D -M --machine --root --file)'{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
114 '(--directory -D -M --machine --root --file)'{-D+,--directory=}'[Show journal files from directory]:directories:_directories' \
64431774
EC
115 '(--directory -D -M --machine --root --file)--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \
116 '(--directory -D -M --machine --root)*--file=[Operate on specified journal files]:file:_files' \
7e83c0e0
WG
117 '--new-id128[Generate a new 128 Bit ID]' \
118 '--header[Show journal header information]' \
119 '--disk-usage[Show total disk usage]' \
120 '--list-catalog[List messages in catalog]' \
121 '--dump-catalog[Dump messages in catalog]' \
122 '--update-catalog[Update binary catalog database]' \
c736283b
JSJ
123 '--setup-keys[Generate a new FSS key pair]' \
124 '--force[Force recreation of the FSS keys]' \
7e83c0e0
WG
125 '--interval=[Time interval for changing the FSS sealing key]:time interval' \
126 '--verify[Verify journal file consistency]' \
127 '--verify-key=[Specify FSS verification key]:FSS key' \
c501ecd7 128 '*::default: _journalctl_none'