{"action":"created","issue":{"url":"https://api.github.com/repos/yyuu/pyenv-virtualenv/issues/45","labels_url":"https://api.github.com/repos/yyuu/pyenv-virtualenv/issues/45/labels{/name}","comments_url":"https://api.github.com/repos/yyuu/pyenv-virtualenv/issues/45/comments","events_url":"https://api.github.com/repos/yyuu/pyenv-virtualenv/issues/45/events","html_url":"https://github.com/yyuu/pyenv-virtualenv/issues/45","id":42020385,"number":45,"title":"Use chpwd hook for _pyenv_virtualenv_hook / internal hook system with pyenv","user":{"login":"blueyed","id":9766,"avatar_url":"https://avatars.githubusercontent.com/u/9766?v=3","gravatar_id":"","url":"https://api.github.com/users/blueyed","html_url":"https://github.com/blueyed","followers_url":"https://api.github.com/users/blueyed/followers","following_url":"https://api.github.com/users/blueyed/following{/other_user}","gists_url":"https://api.github.com/users/blueyed/gists{/gist_id}","starred_url":"https://api.github.com/users/blueyed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blueyed/subscriptions","organizations_url":"https://api.github.com/users/blueyed/orgs","repos_url":"https://api.github.com/users/blueyed/repos","events_url":"https://api.github.com/users/blueyed/events{/privacy}","received_events_url":"https://api.github.com/users/blueyed/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2014-09-05T07:15:24Z","updated_at":"2015-11-12T22:24:23Z","closed_at":null,"body":"I wonder if it would be a good idea to use the `chpwd` hook (instead of `precmd` (for zsh)) with the hook that gets installed via `pyenv virtualenv init -`:\r\n\r\n    _pyenv_virtualenv_hook () {\r\n      if [ -n \"$PYENV_ACTIVATE\" ]\r\n      then\r\n        if [ \"$(pyenv version-name)\" = \"system\" ]\r\n        then\r\n          pyenv deactivate --no-error --verbose\r\n          return 0\r\n        fi\r\n        if [ \"$PYENV_ACTIVATE\" != \"$(pyenv prefix)\" ]\r\n        then\r\n          if pyenv deactivate --no-error --verbose\r\n          then\r\n            pyenv activate --no-error --verbose || unset PYENV_DEACTIVATE\r\n          else\r\n            pyenv activate --no-error --verbose\r\n          fi\r\n        fi\r\n      else\r\n        if [ -z \"$VIRTUAL_ENV\" ] && [ \"$PYENV_DEACTIVATE\" != \"$(pyenv prefix)\" ]\r\n        then\r\n          pyenv activate --no-error --verbose\r\n        fi\r\n      fi\r\n    }\r\n\r\nAlternatively, pyenv itself could have a hook system, where changing the version (e.g. via `pyenv shell`) would notify the pyenv-virtualenv plugin and that could call `activate` then (based on some config).\r\n\r\n\r\n\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/4224688-use-chpwd-hook-for-_pyenv_virtualenv_hook-internal-hook-system-with-pyenv?utm_campaign=plugin&utm_content=tracker%2F335155&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F335155&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/yyuu/pyenv-virtualenv/issues/comments/156256293","html_url":"https://github.com/yyuu/pyenv-virtualenv/issues/45#issuecomment-156256293","issue_url":"https://api.github.com/repos/yyuu/pyenv-virtualenv/issues/45","id":156256293,"user":{"login":"obestwalter","id":263007,"avatar_url":"https://avatars.githubusercontent.com/u/263007?v=3","gravatar_id":"","url":"https://api.github.com/users/obestwalter","html_url":"https://github.com/obestwalter","followers_url":"https://api.github.com/users/obestwalter/followers","following_url":"https://api.github.com/users/obestwalter/following{/other_user}","gists_url":"https://api.github.com/users/obestwalter/gists{/gist_id}","starred_url":"https://api.github.com/users/obestwalter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/obestwalter/subscriptions","organizations_url":"https://api.github.com/users/obestwalter/orgs","repos_url":"https://api.github.com/users/obestwalter/repos","events_url":"https://api.github.com/users/obestwalter/events{/privacy}","received_events_url":"https://api.github.com/users/obestwalter/received_events","type":"User","site_admin":false},"created_at":"2015-11-12T22:24:23Z","updated_at":"2015-11-12T22:24:23Z","body":"@blueyed\r\n\r\n> the concept of \"leave\" events in seperate or the same file: direnv appears to only care about the state of exported vars?!\r\n\r\nLeave events and autostashing in [zsh-autoenv](https://github.com/Tarrasch/zsh-autoenv) look definitely more sophisticated than what direnv has to offer, but I'll keep playing around with direnv for a while as I had set it up already right after reading about it here.\r\n\r\nSpeed is not really a topic for me at the moment as new shells open instantaneously with my current setup (i3wm + roxterm with quite a lot zsh goodness).\r\n\r\nEnough with the off-topicism then :)"}}