Skip to content

Instantly share code, notes, and snippets.

@amitu
Last active March 17, 2016 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitu/ae169bc7f2f4456358c7 to your computer and use it in GitHub Desktop.
Save amitu/ae169bc7f2f4456358c7 to your computer and use it in GitHub Desktop.
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
Copy link

blueyed commented Mar 17, 2016

You don't need python for this..

@amitu
Copy link
Author

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