Skip to content

Instantly share code, notes, and snippets.

Last active Mar 17, 2016
What would you like to do?
ZSH: Print time to execute each command as it is executed.
preexec () {
START="$(python -c 'import time; print time.time()')"
precmd () {
if [ -z ${START} ];
echo -n "Executed [$LAST_CMD: $LAST] in "
python -c "import time; print '%0.3fs.' % (time.time() - $START)"
unset LAST
unset LAST_CMD
unset START

This comment has been minimized.

Copy link

@blueyed blueyed commented Mar 17, 2016

You don't need python for this..


This comment has been minimized.

Copy link
Owner Author

@amitu amitu commented Mar 17, 2016

True. But as long as you are execing any external command, its all the same. Would be interesting if it can be done using only shell builtins tho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment