Skip to content

Commit

Permalink
discover fish complete paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Mar 28, 2024
1 parent 543b6e2 commit 28d0af0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion b2/_internal/_cli/autocomplete_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import logging
import os
import re
import shlex
import shutil
import signal
import subprocess
Expand Down Expand Up @@ -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:
"""
Expand Down

0 comments on commit 28d0af0

Please sign in to comment.