2019-04-05 12:41:35 +03:00
#compdef journalctl -*- shell-script -*-
2020-11-09 07:23:58 +03:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2013-07-29 23:07:21 +04:00
2018-12-24 14:15:38 +03:00
(( $+functions[_journalctl_fields] )) ||
_journalctl_fields() {
2013-07-29 23:07:21 +04:00
local -a journal_fields
journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID}
_{P,U,G}ID _COMM _EXE _CMDLINE
_AUDIT_{SESSION,LOGINUID}
_SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
2013-08-24 16:23:27 +04:00
_SYSTEMD_USER_UNIT USER_UNIT
2013-07-29 23:07:21 +04:00
_SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
_{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
_KERNEL_{DEVICE,SUBSYSTEM}
_UDEV_{SYSNAME,DEVNODE,DEVLINK}
__CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
2013-08-14 22:29:58 +04:00
case $_jrnl_none in
yes) _values -s '=' 'possible fields' \
2018-12-24 14:15:38 +03:00
"${journal_fields[@]}:value:_journalctl_field_values ${words[CURRENT]%%=*}" ;;
2013-08-14 22:29:58 +04:00
*) _describe 'possible fields' journal_fields ;;
esac
2013-07-29 23:07:21 +04:00
}
2018-12-24 14:15:38 +03:00
(( $+functions[_journalctl_none] )) ||
_journalctl_none() {
2013-08-14 22:29:58 +04:00
local -a _commands _files _jrnl_none
2013-08-02 06:35:16 +04:00
# Setting use-cache will slow this down considerably
2020-08-25 05:33:37 +03:00
_commands=( ${(f)"$(_call_program commands "$service $_sys_service_mgr -F _EXE" 2>/dev/null)"} )
2013-08-14 22:29:58 +04:00
_jrnl_none='yes'
2013-07-29 23:07:21 +04:00
_alternative : \
'files:/dev files:_files -W /dev -P /dev/' \
2020-08-25 05:33:37 +03:00
'commands:commands:compadd -a _commands' \
2018-12-24 14:15:38 +03:00
'fields:fields:_journalctl_fields'
2013-07-29 23:07:21 +04:00
}
2018-12-24 14:15:38 +03:00
(( $+functions[_journalctl_field_values] )) ||
_journalctl_field_values() {
2013-07-29 23:07:21 +04:00
local -a _fields cmd
2016-08-13 17:41:22 +03:00
cmd=("journalctl $_sys_service_mgr" "-F ${@[-1]}" "2>/dev/null" )
2016-01-26 02:10:31 +03:00
_fields=$(_call_program fields $cmd[@])
_fields=${_fields//'\'/'\\'}
_fields=${_fields//':'/'\:'}
_fields=( ${(f)_fields} )
2013-07-29 23:07:21 +04:00
typeset -U _fields
_describe 'possible values' _fields
}
2018-12-24 14:15:38 +03:00
(( $+functions[_journalctl_boots] )) ||
_journalctl_boots() {
2013-07-29 23:37:35 +04:00
local -a _bootid _previousboots
2014-09-27 16:48:09 +04:00
_bootid=( ${(f)"$(_call_program bootid "$service -F _BOOT_ID")"} )
2013-07-29 23:37:35 +04:00
_previousboots=( -{1..${#_bootid}} )
_alternative : \
2014-09-27 16:48:09 +04:00
"offsets:boot offsets:compadd -a '_previousboots[1,-2]'" \
"bootid:boot ids:compadd -a _bootid"
2013-07-29 23:37:35 +04:00
}
2016-08-13 17:41:22 +03:00
# Build arguments for "journalctl" to be used in completion.
# Use both --user and --system modes, they are not exclusive.
local -a _modes; _modes=(--user --system)
2016-08-16 19:47:39 +03:00
local -a _modes_with_arg; _modes_with_arg=(--directory -D --file -M --machine --root)
2016-08-13 17:41:22 +03:00
typeset -a _sys_service_mgr
2016-08-16 19:47:39 +03:00
local w k v i=0 n=$#words
2016-08-13 17:41:22 +03:00
while (( i++ < n )); do
w=$words[$i]
if (( $_modes[(I)$w] )); then
_sys_service_mgr+=($w)
else
2016-08-16 19:47:39 +03:00
# Handle options with arguments. "--key=value" and "--key value".
k=${w%%=*}
if (( ${_modes_with_arg[(I)$k]} )); then
v=${w#*=}
if [[ "$k" != "$w" ]]; then
# "--key=value" style.
_sys_service_mgr+=($w)
else
# "--key value" style.
_sys_service_mgr+=($w ${words[((++i))]})
fi
2016-08-13 17:41:22 +03:00
fi
fi
done
2013-07-29 23:07:21 +04:00
_arguments -s \
{-h,--help}'[Show this help]' \
'--version[Show package version]' \
'--no-pager[Do not pipe output into a pager]' \
2019-03-26 02:36:15 +03:00
--no-hostname"[Don't show the hostname of local log messages]" \
2013-07-29 23:07:21 +04:00
{-l,--full}'[Show long fields in full]' \
{-a,--all}'[Show all fields, including long and unprintable]' \
{-f,--follow}'[Follow journal]' \
{-e,--pager-end}'[Jump to the end of the journal in the pager]' \
2013-08-21 07:06:54 +04:00
{-n+,--lines=}'[Number of journal entries to show]:integer' \
2013-07-29 23:07:21 +04:00
'--no-tail[Show all lines, even in follow mode]' \
{-r,--reverse}'[Reverse output]' \
2013-11-08 02:00:52 +04:00
{-o+,--output=}'[Change journal output mode]:output modes:_sd_outputmodes' \
2013-07-29 23:07:21 +04:00
{-x,--catalog}'[Show explanatory texts with each log line]' \
{-q,--quiet}"[Don't show privilege warning]" \
{-m,--merge}'[Show entries from all available journals]' \
2018-12-24 14:15:38 +03:00
{-b+,--boot=}'[Show data only from the specified boot or offset]::boot id or offset:_journalctl_boots' \
2013-10-29 07:43:57 +04:00
'--list-boots[List boots ordered by time]' \
2013-12-18 06:36:27 +04:00
{-k,--dmesg}'[Show only kernel messages from the current boot]' \
2018-12-24 14:15:38 +03:00
{-u+,--unit=}'[Show data only from the specified unit]:units:_journalctl_field_values _SYSTEMD_UNIT' \
'--user-unit=[Show data only from the specified user session unit]:units:_journalctl_field_values USER_UNIT' \
{-p+,--priority=}'[Show only messages within the specified priority range]:priority:_journalctl_field_values PRIORITY' \
{-t+,--identifier=}'[Show only messages with the specified syslog identifier]:identifier:_journalctl_field_values SYSLOG_IDENTIFIER' \
{-c+,--cursor=}'[Start showing entries from the specified cursor]:cursors:_journalctl_field_values __CURSORS' \
2019-02-12 02:19:13 +03:00
'--cursor-file=[Show entries using cursor store in file]:file:_files' \
2018-12-24 14:15:38 +03:00
'--after-cursor=[Start showing entries from after the specified cursor]:cursors:_journalctl_field_values __CURSORS' \
2013-12-18 06:36:27 +04:00
'--since=[Start showing entries on or newer than the specified date]:YYYY-MM-DD HH\:MM\:SS' \
'--until=[Stop showing entries on or older than the specified date]:YYYY-MM-DD HH\:MM\:SS' \
2018-12-24 14:15:38 +03:00
{-F,--field=}'[List all values a certain field takes]:Fields:_journalctl_fields' \
2013-07-29 23:07:21 +04:00
'--system[Show system and kernel messages]' \
'--user[Show messages from user services]' \
2016-08-16 19:42:41 +03:00
'(--directory -D -M --machine --root --file)'{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
'(--directory -D -M --machine --root --file)'{-D+,--directory=}'[Show journal files from directory]:directories:_directories' \
2017-01-27 15:50:40 +03:00
'(--directory -D -M --machine --root --file)--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \
'(--directory -D -M --machine --root)*--file=[Operate on specified journal files]:file:_files' \
2013-07-29 23:07:21 +04:00
'--disk-usage[Show total disk usage]' \
'--dump-catalog[Dump messages in catalog]' \
2019-08-28 08:28:02 +03:00
'--flush[Flush all journal data from /run into /var]' \
2013-12-18 06:36:27 +04:00
'--force[Force recreation of the FSS keys]' \
2019-08-28 08:28:02 +03:00
'--header[Show journal header information]' \
2013-07-29 23:07:21 +04:00
'--interval=[Time interval for changing the FSS sealing key]:time interval' \
2019-08-28 08:28:02 +03:00
'--list-catalog[List messages in catalog]' \
'--new-id128[Generate a new 128 Bit ID]' \
'--rotate[Request immediate rotation of the journal files]' \
'--setup-keys[Generate a new FSS key pair]' \
'--sync[Synchronize unwritten journal messages to disk]' \
'--update-catalog[Update binary catalog database]' \
'--vacuum-files=[Leave only the specified number of journal files]:integer' \
'--vacuum-size=[Reduce disk usage below specified size]:bytes' \
'--vacuum-time=[Remove journal files older than specified time]:time' \
2013-07-29 23:07:21 +04:00
'--verify-key=[Specify FSS verification key]:FSS key' \
2019-08-28 08:28:02 +03:00
'--verify[Verify journal file consistency]' \
2018-12-24 14:15:38 +03:00
'*::default: _journalctl_none'