mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-06-05 05:03:16 +02:00
[plugins/runtime] Add simple plugin counting a command's execution time
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
parent
cafa657469
commit
07f4f79779
1 changed files with 26 additions and 0 deletions
26
plugins/runtime/runtime.plugin.zsh
Normal file
26
plugins/runtime/runtime.plugin.zsh
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Simple plugin to calculate the time since the last command was run.
|
||||
# This is a proxy to the runtime when used in the prompt.
|
||||
#
|
||||
# Copyright, 2018, Olivier Mehani <shtrom+zsh@ssji.net>, MIT licensed
|
||||
#
|
||||
local _RUNTIME_FILE=$(umask 7077; mktemp /tmp/zsh_runtime.$$.XXXXXX)
|
||||
|
||||
function runtime() {
|
||||
local last=$(cat ${_RUNTIME_FILE})
|
||||
if [[ -n $last ]]; then
|
||||
echo "$(date '+%s')-$last" | bc -ql
|
||||
echo > ${_RUNTIME_FILE}
|
||||
fi
|
||||
}
|
||||
|
||||
function runtime_preexec() {
|
||||
date '+%s' > ${_RUNTIME_FILE}
|
||||
}
|
||||
|
||||
function runtime_zshexit() {
|
||||
rm ${_RUNTIME_FILE}
|
||||
}
|
||||
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook preexec runtime_preexec
|
||||
add-zsh-hook zshexit runtime_zshexit
|
||||
Loading…
Add table
Add a link
Reference in a new issue