From 32b5dfe58a0bb1c0ce433ed6e6f74c618783df95 Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Mon, 6 Sep 2021 09:18:45 +0200 Subject: [PATCH] Use tool versions file to colorize `ls --details` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, environment Python versions in the `vf ls --details` list were only considered to be up-to-date (i.e., displayed in green) when a given environment's Python version is greater or equal to the default Python version returned by `__vfsupport_get_default_python()`. If you have some environments on older but fully-supported Python versions, those would show up in yellow even though they should be considered up-to-date. With the changes in this commit, given a `~/.tool-versions` file that contains the following line: python 3.9.7 3.8.12 3.7.11 3.6.14 … any environment's Python version that matches one of the specified versions will be considered up-to-date and displayed in green. --- docs/usage.rst | 7 +++++++ virtualfish/virtual.fish | 26 +++++++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 9dc9d72..026cc16 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -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 diff --git a/virtualfish/virtual.fish b/virtualfish/virtual.fish index dc8986f..63225b1 100644 --- a/virtualfish/virtual.fish +++ b/virtualfish/virtual.fish @@ -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