systemctl: add --timestamp to change timestamp print format

Timestamps for unit start/stop are recorded with microsecond granularity,
but status and show truncate to second granularity by default.
Add a --timestamp=pretty|us|utc option to allow including the microseconds
or to use the UTC TZ to all timestamps printed by systemctl.
This commit is contained in:
Luca Boccassi
2020-08-19 15:30:13 +01:00
parent 7b3eb5c97e
commit 46ad9c5378
4 changed files with 58 additions and 12 deletions
+4 -1
View File
@@ -127,7 +127,7 @@ _systemctl () {
--quiet -q --system --user --version --runtime --recursive -r --firmware-setup
--show-types -i --ignore-inhibitors --plain --failed --value --fail --dry-run --wait'
[ARG]='--host -H --kill-who --property -p --signal -s --type -t --state --job-mode --root
--preset-mode -n --lines -o --output -M --machine --message'
--preset-mode -n --lines -o --output -M --machine --message --timestamp'
)
if __contains_word "--user" ${COMP_WORDS[*]}; then
@@ -176,6 +176,9 @@ _systemctl () {
--machine|-M)
comps=$( __get_machines )
;;
--timestamp)
comps='pretty us µs utc us+utc µs+utc'
;;
esac
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
+8
View File
@@ -431,6 +431,13 @@ done
_values -s , "${_modes[@]}"
}
(( $+functions[_systemctl_timestamp] )) ||
_systemctl_timestamp() {
local -a _styles
_styles=(help pretty us µs utc us+utc µs+utc)
_values -s , "${_styles[@]}"
}
# Build arguments for "systemctl" to be used in completion.
local -a _modes; _modes=("--user" "--system")
# Use the last mode (they are exclusive and the last one is used).
@@ -471,4 +478,5 @@ _arguments -s \
'--firmware-setup[Tell the firmware to show the setup menu on next boot]' \
'--plain[When used with list-dependencies, print output as a list]' \
'--failed[Show failed units]' \
'--timestamp=[Change format of printed timestamps]:style:_systemctl_timestamp' \
'*::systemctl command:_systemctl_commands'