I love zsh. I love it even more because of oh-my-zsh, but that's a post for a different time. zsh has some great features built in, and the one I'd like to write about today is REPORTTIME.


As you work on more and more complex projects, especially in compiled languages or long running simulations, etc., commands take longer and longer to run. And to know that these commands may be bottlenecks worth optimizing (parallelizing tests and simulations, getting a system like ccache for speeding up compiles), you need to know how long these commands are taking.


Running everything through time is a pain, and nobody can remember to do that every time they run a command. Luckily, has a built in way to do just that in a non-obtrusive way. Say you would like to know whenever a shell command has taken longer than 10 seconds to run. Set REPORTTIME to 10 in your .zshrc, like so:


And then, every time you run a command that takes longer than 10 seconds, the command will display the time it took as if you ran it through time.

Even More

With enough time on your hands, you can set arbitrary hooks to run when REPORTTIME is triggered. There's some examples of people doing this here for Linux and here for OSX.

Thanks to Markus Prinz and his post on this topic for enlightening me.