diff --git a/b2/_internal/_cli/autocomplete_install.py b/b2/_internal/_cli/autocomplete_install.py index bce25401..fe51ab5d 100644 --- a/b2/_internal/_cli/autocomplete_install.py +++ b/b2/_internal/_cli/autocomplete_install.py @@ -14,6 +14,7 @@ import logging import os import re +import shlex import shutil import signal import subprocess @@ -189,7 +190,24 @@ def force_enable(self, completion_script: Path) -> None: def get_script_path(self) -> Path: """Get autocomplete script path for the given program, common logic.""" - return Path("~/.config/fish/completions/").expanduser() / f"{self.prog}.fish" + complete_paths = [ + Path(p) for p in shlex.split( + subprocess.run( + [self.shell_exec, '-c', 'echo $fish_complete_path'], + timeout=30, + text=True, + check=True, + capture_output=True + ).stdout + ) + ] + user_path = Path("~/.config/fish/completions").expanduser() + if complete_paths: + target_path = user_path if user_path in complete_paths else complete_paths[0] + else: + logger.warning("$fish_complete_path is empty, falling back to %r", user_path) + target_path = user_path + return target_path / f"{self.prog}.fish" def is_enabled(self) -> bool: """