Skip to content

shell completion installs #133

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged

shell completion installs #133

merged 1 commit into from
Jun 26, 2025

Conversation

cwlbraa
Copy link
Collaborator

@cwlbraa cwlbraa commented Jun 25, 2025

requires #130

this PR installs shell completions using homebrew post install hooks and provides instructions on how to install them as install.sh output.

complexities:

  • bash: there are canonical locations for bash, but those locations require the (very standard) bash-completion plugin.
    • in homebrew, we'll just assume you have that package or if you're using bash over default zsh, you'll guess that you need it.
  • zsh: there are no canonical locations, but you can look up locations from fpath if your shell is all configured (ohmyzsh, antigen, etc).
    • homebrew documents how things need to be set up for zsh completions, and so long as the user has eval "$(brew shellenv)" in their zshrc, we can write to $(brew --prefix)/share/zsh/site-functions pretty blindly
  • fish is friendly so it's got canonical paths 🎉

because it's complex to detect what zsh/bash setups a given installer has from inside the installer script, we instead have the install script tell users both the "dumb" rc-centric way to install, and the most common "managed" way.

one alternative approach that folks have talked about is putting this in a cu init subcommand or similar. we could do that, but it has all the same difficulties that come with putting this in autoinstalling from our bash-specific install script. there are too many possible shells, userspace package managers, and plugin frameworks and custom configurations (including the absence of them).

NOTE: i haven't tested the homebrew tap, don't merge this without testing it on a fork

log_info "To enable shell completions, run:"
echo " Bash (with bash-completion): $binary completion bash > ~/.local/share/bash-completion/completions/cu"
echo " Bash (unconfigured): echo 'source <($binary completion bash)' >> ~/.bashrc"
echo " Zsh (with compinit and a writable fpath[1]): $binary completion zsh > \"\${fpath[1]}/_cu\""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Docker adds in zshrc, an fpath as the first entry. But i don't want to add cu's completion to my docker's completion folder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤔 under some package managers fpath[1] isn't gonna be user-writable either, so unideal in several situations.

can i get a citation for the docker approach?

@cwlbraa cwlbraa force-pushed the shell-completion-installs branch from 52162d8 to 0a40dd6 Compare June 26, 2025 18:11
@cwlbraa
Copy link
Collaborator Author

cwlbraa commented Jun 26, 2025

tested homebrew on my fork https://github.com/cwlbraa/homebrew-tap/commits/main/, working correctly and installing cu completions at least for zsh.

if you've already got completions in that brew directory, it throws this:

Error: It seems there is already a Zsh Completion at '/opt/homebrew/share/zsh/site-functions/_cu'.

but after deleting that file and reinstalling the error goes away.

@cwlbraa cwlbraa merged commit cb39d89 into main Jun 26, 2025
2 checks passed
@aluzzardi aluzzardi deleted the shell-completion-installs branch June 26, 2025 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants