| 1 |
#compdef journalctl |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 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=( ${(f)"$(_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 ' \ |
| 33 |
'commands:commands:compadd -a _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 |
(( $+functions[_journalctl_facilities] )) || |
| 60 |
_journalctl_facilities() { |
| 61 |
local -a _journalctl_facilities |
| 62 |
_journalctl_facilities=(help kern user mail daemon auth syslog lpr news uucp cron authpriv ftp local0 local1 local2 local3 local4 local5 local6 local7) |
| 63 |
_describe 'possible values' _journalctl_facilities |
| 64 |
} |
| 65 |
|
| 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 |
|
| 73 |
# Build arguments for "journalctl" to be used in completion. |
| 74 |
# Use both --user and --system modes, they are not exclusive. |
| 75 |
local -a _modes; _modes=(--user --system) |
| 76 |
local -a _modes_with_arg; _modes_with_arg=(--directory -D -i --file -M --machine --root) |
| 77 |
typeset -a _sys_service_mgr |
| 78 |
local w k v i=0 n=$#words |
| 79 |
while (( i++ < n )); do |
| 80 |
w=$words[$i] |
| 81 |
if (( $_modes[(I)$w] )); then |
| 82 |
_sys_service_mgr+=($w) |
| 83 |
else |
| 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 |
| 95 |
fi |
| 96 |
fi |
| 97 |
done |
| 98 |
_arguments -s \ |
| 99 |
'(- *)'{-h,--help}'[Show this help]' \ |
| 100 |
'(- *)--version[Show package version]' \ |
| 101 |
'--no-pager[Do not pipe output into a pager]' \ |
| 102 |
'(-W --no-hostname)'{-W,--no-hostname}"[Don't show the hostname of log messages]" \ |
| 103 |
'(-l --full)'{-l,--full}'[Show long fields in full]' \ |
| 104 |
'(-a --all)'{-a,--all}'[Show all fields, including long and unprintable]' \ |
| 105 |
'(-f --follow)'{-f,--follow}'[Follow journal]' \ |
| 106 |
'(-e --pager-end)'{-e,--pager-end}'[Jump to the end of the journal in the pager]' \ |
| 107 |
'(-n --lines)'{-n+,--lines=}'[Number of journal entries to show]:integer' \ |
| 108 |
'--no-tail[Show all lines, even in follow mode]' \ |
| 109 |
'(-r --reverse)'{-r,--reverse}'[Reverse output]' \ |
| 110 |
'(-o --output)'{-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \ |
| 111 |
'(-x --catalog)'{-x,--catalog}'[Show explanatory texts with each log line]' \ |
| 112 |
'(-q --quiet)'{-q,--quiet}"[Don't show privilege warning]" \ |
| 113 |
'(-m --merge)'{-m,--merge}'[Show entries from all available journals]' \ |
| 114 |
'(-b --boot)'{-b+,--boot=}'[Show data only from the specified boot or offset]::boot id or offset:_journalctl_boots' \ |
| 115 |
'--list-boots[List boots ordered by time]' \ |
| 116 |
'(-k --dmesg)'{-k,--dmesg}'[Show only kernel messages from the current boot]' \ |
| 117 |
'(-u --unit)'{-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)'{-p+,--priority=}'[Show only messages within the specified priority range]:priority:_journalctl_field_values PRIORITY' \ |
| 120 |
'--facility=[Filter messages by facility]:facility:_journalctl_facilities' \ |
| 121 |
'(-t --identifier)'{-t+,--identifier=}'[Filter messages by syslog identifier]:identifier:_journalctl_field_values SYSLOG_IDENTIFIER' \ |
| 122 |
'(-c --cursor)'{-c+,--cursor=}'[Start showing entries from the specified cursor]:cursors:_journalctl_field_values __CURSORS' \ |
| 123 |
'--cursor-file=[Show entries using cursor stored in file]:file:_files' \ |
| 124 |
'--after-cursor=[Start showing entries from after the specified cursor]:cursors:_journalctl_field_values __CURSORS' \ |
| 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' \ |
| 127 |
'(-g --grep)'{-g+,--grep=}'[Show entries with MESSAGE field matching PCRE pattern]' \ |
| 128 |
'--case-sensitive=[Force case sensitive or insensitive matching]:boolean:(true false)' \ |
| 129 |
'(-F --field)'{-F,--field=}'[List all values a certain field takes]:Fields:_journalctl_fields' \ |
| 130 |
'--system[Show system and kernel messages]' \ |
| 131 |
'--user[Show messages from user services]' \ |
| 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' \ |
| 134 |
'(--directory -D -M --machine --root --file)--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \ |
| 135 |
'(--directory -D -M --machine --root)*'{-i+,--file=}'[Operate on specified journal files]:file:_files' \ |
| 136 |
'--disk-usage[Show total disk usage]' \ |
| 137 |
'--dump-catalog[Dump messages in catalog]' \ |
| 138 |
'--flush[Flush all journal data from /run into /var]' \ |
| 139 |
'--force[Force recreation of the FSS keys]' \ |
| 140 |
'--header[Show journal header information]' \ |
| 141 |
'--interval=[Time interval for changing the FSS sealing key]:time interval' \ |
| 142 |
'--list-catalog[List messages in catalog]' \ |
| 143 |
'--list-namespaces[List available journal namespaces]' \ |
| 144 |
'--namespace[Show journal data from specified namespace]:namespace:_journalctl_namespaces' \ |
| 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' \ |
| 153 |
'--verify-key=[Specify FSS verification key]:FSS key' \ |
| 154 |
'--verify[Verify journal file consistency]' \ |
| 155 |
'*::default: _journalctl_none' |