From 4cc7582359feba106a9852ef7f51ec60d870c761 Mon Sep 17 00:00:00 2001 From: Martin Zuther Date: Tue, 5 Jan 2021 15:01:41 +0100 Subject: [PATCH] handle missing generic Python binary ("python") gracefully --- fish_prompt.fish | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index e0a653e..2179d3a 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -847,7 +847,19 @@ function __bobthefish_prompt_rubies -S -d 'Display current Ruby information' end function __bobthefish_virtualenv_python_version -S -d 'Get current Python version' - switch (python --version 2>&1 | tr '\n' ' ') + set -l python_version + + # try preferred Python version first + if [ (which python) ] + set python_version (python --version 2>&1 | tr '\n' ' ') + # choose Python 3 over Python 2 + else if [ (which python3) ] + set python_version (python3 --version 2>&1 | tr '\n' ' ') + else + set python_version (python2 --version 2>&1 | tr '\n' ' ') + end + + switch $python_version case 'Python 2*PyPy*' echo $pypy_glyph case 'Python 3*PyPy*'