From 9d05130f9505014ebf2aeffadec719c8aa16c3d4 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 3 Nov 2023 19:31:06 +0300 Subject: [PATCH] bash_completion: Generate the list of Python/pip versions --- .bash_completion.d/python-pip | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/.bash_completion.d/python-pip b/.bash_completion.d/python-pip index 57aaf06..f6e3126 100644 --- a/.bash_completion.d/python-pip +++ b/.bash_completion.d/python-pip @@ -1,17 +1,14 @@ -delegate_completion python python2.7 python3.4 python3.5 python3.6 python3.7 python3.8 python3.9 python3.10 python3.11 python3.12 +PY_VERSIONS="2,2.7,3," +PY_VERSIONS+="$(eval echo 3.{`seq -s, 4 12`} | sed 's/ /,/g')" -if type -p pip >/dev/null 2>&1; then - _PIP=pip -elif type -p pip3 >/dev/null 2>&1; then - _PIP=pip3 -fi +eval delegate_completion python python{$PY_VERSIONS} -if [ -n "$_PIP" ]; then - _pip_completion_loader() { - eval "`$_PIP completion --bash`" - complete -F _pip_completion pip pip2 pip2.7 pip3 pip3.4 pip3.5 pip3.6 pip3.7 pip3.8 pip3.9 pip3.10 pip3.11 pip3.12 - unset _pip_completion_loader - return 124 - } - complete -F _pip_completion_loader pip pip2 pip2.7 pip3 pip3.4 pip3.5 pip3.6 pip3.7 pip3.8 pip3.9 pip3.10 pip3.11 pip3.12 -fi +_pip_completion_loader() { + if [ "`type -t _pip_completion`" != function ]; then + eval "`pip3 completion --bash`" + fi + eval complete -F _pip_completion pip pip{$PY_VERSIONS} + unset _pip_completion_loader PY_VERSIONS + return 124 +} +eval complete -F _pip_completion_loader pip pip{$PY_VERSIONS} -- 2.39.2