fish and pyenv

In the category of “things that ought to work, but do not”: there is a pyenv integration for the fish shell, but it just yells at you:

$ pyenv activate env-name
pyenv-virtualenv: prompt changing not working for fish.

Though this is very sad, I assume this is because pyenv — a command, not a function — can’t alter the current environment, a function is required. I added this code to my fish config:

function pyact
  set -l env_name $argv[1]
  source (psub < $PYENV_ROOT/versions/$env_name/bin/

# auto-complete for above; picks up new virtualenvs when you start a new shell
for ve_name in (find $PYENV_ROOT/versions -type l -depth 1)
  complete -c pyact -f -a (basename $ve_name)

Now tab-completion works for the existing virutalenvs:

$ pyact <tab>
ansible  def    dps


Author: paul

Leave a Reply

Your email address will not be published. Required fields are marked *