Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autocompletions for vf new -p and vf upgrade -p with asdf or pyenv installs #220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ For asdf_, Pyenv_, and Pythonz_ , in addition to passing option flags such as
``-p python3.8`` or ``-p python3.9.0a4``, you can even get away with specifying
just the version numbers, such as ``-p 3.8`` or ``-p 3.9.0a4``.

If you would like to get autocompletions for ``vf new -p`` and ``vf upgrade -p``
with Python versions installed via asdf_ or pyenv_, execute the following
interactively. For asdf_::

set -Ux VIRTUALFISH_PYVERSION_COMPLETION "asdf"

For pyenv_::

set -Ux VIRTUALFISH_PYVERSION_COMPLETION "pyenv"

After reloading your shell (e.g. via ``exec fish``) numbers of Python versions
installed via asdf_ or pyenv_ will be autocompleted. Because this is using fish's
`universal variables`_, you only need to execute this once and there is no need
to add this line to your ``config.fish`` file. However, if you would like these
autocompletions set up automatically on a new machine, you could add the
following to your config (adjust by picking either asdf_ or pyenv_)::

if test -z "$VIRTUALFISH_PYVERSION_COMPLETION"
set -Ux VIRTUALFISH_PYVERSION_COMPLETION "asdf"/"pyenv"/"pyorg"
exec fish
end

.. _configuration_variables:

Upgrading Virtual Environments
Expand Down Expand Up @@ -149,3 +171,4 @@ you want those changes to take effect for the current shell session.
.. _asdf: https://asdf-vm.com/
.. _Pyenv: https://github.com/pyenv/pyenv
.. _Pythonz: https://github.com/saghul/pythonz
.. _universal variables: https://fishshell.com/docs/current/tutorial.html#universal-variables
13 changes: 13 additions & 0 deletions virtualfish/virtual.fish
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,19 @@ function __vfsupport_setup_autocomplete --on-event virtualfish_did_setup_plugins
complete -x -c vf -n '__vfcompletion_using_command connect' -a "(vf ls)"
complete -x -c vf -n '__vfcompletion_using_command rm' -a "(vf ls)"
complete -x -c vf -n '__vfcompletion_using_command upgrade' -a "(vf ls)"
# Optional: Autocomplete `vf new -p` and `vf upgrade -p` with Python versions installed via
# asdf or pyenv. To use, interactively execute `set -Ux VIRTUALFISH_PYVERSION_COMPLETION <"asdf"/"pyenv">`
# and reload your shell
if set -q VIRTUALFISH_PYVERSION_COMPLETION
if test $VIRTUALFISH_PYVERSION_COMPLETION = "asdf"
complete -x -c vf -n '__vfcompletion_using_command new' -s p -l python -a "(asdf list python 2> /dev/null | sed -e 's/^[[:space:]]*//')"
complete -x -c vf -n '__vfcompletion_using_command upgrade' -s p -l python -a "(asdf list python 2> /dev/null | sed -e 's/^[[:space:]]*//')"
else if test $VIRTUALFISH_PYVERSION_COMPLETION = "pyenv"
complete -x -c vf -n '__vfcompletion_using_command new' -s p -l python -a "(pyenv versions --bare)"
complete -x -c vf -n '__vfcompletion_using_command upgrade' -s p -l python -a "(pyenv versions --bare)"
end
end

end

function __vfsupport_get_default_python --description "Return Python interpreter defined in variables, if any"
Expand Down