From 07f4f79779e7b707fcfabf06bd45205edba7f0ce Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Thu, 10 May 2018 21:15:42 +1000 Subject: [PATCH] [plugins/runtime] Add simple plugin counting a command's execution time Signed-off-by: Olivier Mehani --- plugins/runtime/runtime.plugin.zsh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 plugins/runtime/runtime.plugin.zsh diff --git a/plugins/runtime/runtime.plugin.zsh b/plugins/runtime/runtime.plugin.zsh new file mode 100644 index 000000000..ef497e6d9 --- /dev/null +++ b/plugins/runtime/runtime.plugin.zsh @@ -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 , 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