Skip to content

Commit

Permalink
Merge pull request #212 from justinmayer/asdf-tool-versions
Browse files Browse the repository at this point in the history
Use tool versions file to colorize `ls --details`
  • Loading branch information
justinmayer committed Sep 7, 2021
2 parents f845c9d + 32b5dfe commit b8852ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
7 changes: 7 additions & 0 deletions docs/usage.rst
Expand Up @@ -76,6 +76,13 @@ To understand which environments might be outdated/broken, run::

vf ls --details

You can maintain a list of target Python versions via a line such as the
following in a ``~/.tool-versions`` file::

python 3.9.7 3.8.12 3.7.11 3.6.14

Environment Python versions that match one of those versions will be shown as
up-to-date (green). If target Python versions are not specified in that file,
VirtualFish compares environment Python versions to the current default Python
version, as specified by the ``VIRTUALFISH_DEFAULT_PYTHON`` variable (see
below), if defined. To perform a minor (point-release) upgrade to the
Expand Down
26 changes: 21 additions & 5 deletions virtualfish/virtual.fish
Expand Up @@ -343,19 +343,35 @@ function __vf_ls --description "List all available virtual environments"
for p in */bin/python
if set -q _flag_details
set -l env_python_version
# Check whether environment's Python is busted
__vfsupport_check_python --pip "$VIRTUALFISH_HOME/$p"
if test $status -eq 0
set env_python_version ("$VIRTUALFISH_HOME/$p" -V | string split " ")[2]
__vfsupport_compare_py_versions $env_python_version $default_python_version
if test $status -eq 1
set env_python_version (set_color yellow)$env_python_version$normal
# If ASDF tool version list is available, retrieve specified Python versions
if test -e ~/.tool-versions
set python_versions (cat ~/.tool-versions | grep python | sed "s|python ||")
end
# If preferred Python versions are specified in ASDF tool version list,
# display in green if current env's Python matches one of those versions (else yellow).
if test -n "$python_versions"
if string match --entire --quiet "$env_python_version" "$python_versions"
set env_python_version $green$env_python_version$normal
else
set env_python_version (set_color yellow)$env_python_version$normal
end
# Otherwise, infer default Python version and compare to that
else
set env_python_version $green$env_python_version$normal
__vfsupport_compare_py_versions $env_python_version $default_python_version
if test $status -eq 1
set env_python_version (set_color yellow)$env_python_version$normal
else
set env_python_version $green$env_python_version$normal
end
end
else
set env_python_version $red"broken"$normal
end
printf "%-33s (%s)\n" $p $env_python_version
printf "%-33s %s\n" $p $env_python_version
else
# No --details flag, so just print the virtual environment names
echo $p
Expand Down

0 comments on commit b8852ec

Please sign in to comment.