Skip to content

Instantly share code, notes, and snippets.

@amitu amitu/.zshrc
Last active Mar 17, 2016

Embed
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()')"
LAST_CMD=$1
}
precmd () {
LAST=$?
if [ -z ${START} ];
then
else
echo -n "Executed [$LAST_CMD: $LAST] in "
python -c "import time; print '%0.3fs.' % (time.time() - $START)"
fi
unset LAST
unset LAST_CMD
unset START
}
@blueyed

This comment has been minimized.

Copy link

commented Mar 17, 2016

You don't need python for this..

@amitu

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.