diff --git a/HISTORY.rst b/HISTORY.rst index a2c8f297..6c313133 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -35,6 +35,7 @@ PlatformIO Core 6 * Allowed to ``Import("projenv")`` in a library extra script (`issue #4305 `_) * Improved a serial port finder for `Black Magic Probe `__ (`issue #4023 `_) * Improved a serial port finder for a board with predefined HWIDs +* Warn about incompatible Bash version for the `Shell Completion `__ (`issue #4326 `_) * Fixed an issue when the `build_unflags `__ operation ignores a flag value (`issue #4309 `_) * Fixed an issue when the `build_unflags `__ option was not applied to the ``ASPPFLAGS`` scope * Fixed an issue on Windows OS when flags were wrapped to the temporary file while generating the `Compilation database "compile_commands.json" `__ diff --git a/platformio/system/completion.py b/platformio/system/completion.py index 3ea80b99..3192021c 100644 --- a/platformio/system/completion.py +++ b/platformio/system/completion.py @@ -13,6 +13,8 @@ # limitations under the License. import os +import re +import subprocess from enum import Enum import click @@ -26,6 +28,14 @@ class ShellType(Enum): BASH = "bash" +def get_bash_version(): + result = subprocess.run(["bash", "--version"], capture_output=True, check=True) + match = re.search(r"version\s+(\d+)\.(\d+)", result.stdout.decode()) + if match: + return (int(match.group(1)), int(match.group(2))) + return (0, 0) + + def get_completion_install_path(shell): home_dir = os.path.expanduser("~") prog_name = click.get_current_context().find_root().info_name @@ -59,6 +69,8 @@ def is_completion_code_installed(shell, path): def install_completion_code(shell, path): + if shell == ShellType.BASH and get_bash_version() < (4, 4): + raise click.ClickException("The minimal supported Bash version is 4.4") if is_completion_code_installed(shell, path): return None append = shell != ShellType.FISH