set -x VIRTUAL_ENV_DISABLE_PROMPT true

# Autosource python virtualenv
function __autovenv_python --on-variable PWD
  set -l base $PWD
  set -l has_venv false

  while test $base != '/'
    if test -f $base/.venv/bin/activate.fish
      set has_venv $base/.venv
      break
    end
    set base (dirname $base)
  end

  if test -n "$VIRTUAL_ENV" -a $has_venv = 'false'
    deactivate
  else if test $has_venv != 'false'
    if test -z "$VIRTUAL_ENV" -o "$VIRTUAL_ENV" != "$has_env"
      source "$has_venv/bin/activate.fish"
    end
  end
end


