Skip to content

Commit

Permalink
More robust check of bash version (#2639)
Browse files Browse the repository at this point in the history
  • Loading branch information
koliyo authored Nov 9, 2024
1 parent 26aa7bf commit 273fb90
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Unreleased
:issue:`2632`
- Fix ``click.echo(color=...)`` passing ``color`` to coloroma so it can be
forced on Windows. :issue:`2606`.

- More robust bash version check, fixing problem on Windows with git-bash.
:issue:`2638`

Version 8.1.7
-------------
Expand Down
15 changes: 11 additions & 4 deletions src/click/shell_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,19 @@ class BashComplete(ShellComplete):

@staticmethod
def _check_version() -> None:
import shutil
import subprocess

output = subprocess.run(
["bash", "-c", 'echo "${BASH_VERSION}"'], stdout=subprocess.PIPE
)
match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode())
bash_exe = shutil.which("bash")

if bash_exe is None:
match = None
else:
output = subprocess.run(
[bash_exe, "--norc", "-c", 'echo "${BASH_VERSION}"'],
stdout=subprocess.PIPE,
)
match = re.search(r"^(\d+)\.(\d+)\.\d+", output.stdout.decode())

if match is not None:
major, minor = match.groups()
Expand Down

0 comments on commit 273fb90

Please sign in to comment.