Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix sourcing of completion path for Git Bash #801

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions typer/_completion_shared.py
Expand Up @@ -100,13 +100,13 @@ def install_bash(*, prog_name: str, complete_var: str, shell: str) -> Path:
# It seems bash-completion is the official completion system for bash:
# Ref: https://www.gnu.org/software/bash/manual/html_node/A-Programmable-Completion-Example.html
# But installing in the locations from the docs doesn't seem to have effect
completion_path = Path.home() / f".bash_completions/{prog_name}.sh"
completion_path = Path.home() / ".bash_completions" / f"{prog_name}.sh"
Copy link
Collaborator Author

@svlandeg svlandeg Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this particular fix is not required to solve the issue on my end (in fact, it makes no difference). I just think it's safer to always use the Pathlib separator / instead of the literal "/".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really makes no difference because Pathlib perfectly understands / in paths 馃槉 it's designed to be cross-platform

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I think you're right - it makes no difference because Pathlib will deal with the literal string correctly, too. Honestly I'd still prefer the edit for esthetic reasons (part of the same path is using /, the other part is using "/") but I don't feel strongly. Will leave it up to Tiangolo - and either way as I said this is not actually related to the bug fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I also think it's more esthetic this way 馃槈 just pointing out it doesn't really make it any safer

rc_path = Path.home() / ".bashrc"
rc_path.parent.mkdir(parents=True, exist_ok=True)
rc_content = ""
if rc_path.is_file():
rc_content = rc_path.read_text()
completion_init_lines = [f"source {completion_path}"]
completion_init_lines = [f"source '{completion_path}'"]
svlandeg marked this conversation as resolved.
Show resolved Hide resolved
for line in completion_init_lines:
if line not in rc_content: # pragma: no cover
rc_content += f"\n{line}"
Expand Down