robbyrussell/oh-my-zsh — pull request #2275 by wjv (2013-11-22 14:18:31+00:00)
Title: Use precmd hook instead of chpwd for updating OS X proxy icon

I'm not an oh-my-zsh user, but I have for years used the exact same trick to update the proxy icon in the OS X Terminal title bar when using zsh. I first came across it in this MacOSXHints post:

http://hints.macworld.com/article.php?story=20110722211753852

Recently I realised that a problem I was observing with the (Python) virtualenvwrapper tool could be traced back to this function. The problem is documented in this issue I filed (while mistakenly believing the problem to lie with virtualenvwrapper):

https://bitbucket.org/dhellmann/virtualenvwrapper/issue/216/lsvirtualenv-and-workon-output-broken-in

The solution I'm proposing here is to use the precmd hook instead of chpwd. This resolves the actual issue, which is that a bunch of text (wrapped in control characters) was spewed to STDOUT upon returning from a subshell in which the working directory was changed. (In theory, other 3rd party applications might also be affected.)

It does, of course, mean that the function to update the proxy icon will be executed a great deal more frequently, though that shouldn't be an issue on a modern system.