Skip to content

Make CLI completion generation dynamic, not hard-coded - #1285

Merged
kurtmckee merged 1 commit into
mainfrom
dynamic-cli-completions
Sep 3, 2026
Merged

Make CLI completion generation dynamic, not hard-coded#1285
kurtmckee merged 1 commit into
mainfrom
dynamic-cli-completions

Conversation

@kurtmckee

Copy link
Copy Markdown
Member

Exactly what it says on the tin.

@kurtmckee kurtmckee self-assigned this Sep 3, 2026
@kurtmckee kurtmckee added the no-news-is-good-news This change does not require a news file label Sep 3, 2026
@kurtmckee
kurtmckee force-pushed the dynamic-cli-completions branch from 088a1aa to caa4174 Compare September 3, 2026 15:43
if "FISH_VERSION" in os.environ:
cls = FishComplete
elif "ZSH_VERSION" in os.environ:
cls = ZshComplete

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we restore the older zsh check? If you prefer, we could make it the behavior for all three shells.

I have a stock install of zsh as my login shell, and no ZSH_VERSION variable is present.

I've forgotten most of the details about the shell behaviors for these variables, but they aren't guaranteed to be present. (And, of course, if I run bash from a zsh session, I get SHELL=/bin/zsh, and vice-versa for a bash shell session with SHELL=/bin/bash! So it's not possible to do it right all of the time.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The zsh docs suggested that ZSH_VERSION was guaranteed to be set by the shell, so I cannot account for this discrepancy. Further, I found that when I ran fish locally, it inherited SHELL=/usr/bin/bash, which made me think that this wasn't reliable.

It's far more preferable to remove the auto-detection logic, but since that's not the point of this PR I've added back in the SHELL-based check.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, crumbs. Turns out ZSH_VERSION and FISH_VERSION don't seem to operate as exported environment variables, so they can't be relied on. Pulled that code entirely out.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Breadcrumb for time-travelers:
We figured things out a bit more. The version vars aren't exported by shells, so they're probably never set in the python process. Probably this "just doesn't work", but nobody has noticed because the SHELL-reading works well enough.

@kurtmckee
kurtmckee force-pushed the dynamic-cli-completions branch from caa4174 to 7cc3305 Compare September 3, 2026 16:24
@kurtmckee
kurtmckee force-pushed the dynamic-cli-completions branch from 7cc3305 to 76867de Compare September 3, 2026 16:35
@kurtmckee
kurtmckee merged commit 451b1fc into main Sep 3, 2026
6 checks passed
@kurtmckee
kurtmckee deleted the dynamic-cli-completions branch September 3, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-news-is-good-news This change does not require a news file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants