Skip to content

Conversation

twobiers
Copy link

@twobiers twobiers commented May 7, 2025

This PR adds a positional argument to the InstallCompletions command for choosing the shell.
This allows e.g. to put source <$(./cli completions bash) in ~/.bashrc and source <$(./cli completions zsh) into ~/.zshrc

Tested locally with the Crossplane CLI:

# zsh is my login shell
$ crossplane completions
autoload -U +X bashcompinit && bashcompinit
complete -C /Users/thund/Repos/privat/crossplane/crossplane crossplane

$ crossplane bash
complete -C /Users/thund/Repos/privat/crossplane/crossplane crossplane

$ crossplane zsh
autoload -U +X bashcompinit && bashcompinit
complete -C /Users/thund/Repos/privat/crossplane/crossplane crossplane

$ crossplane fish
function __complete_crossplane
    set -lx COMP_LINE (commandline -cp)
    test -z (commandline -ct)
    and set COMP_LINE "$COMP_LINE "
    /Users/thund/Repos/privat/crossplane/crossplane
end
complete -f -c crossplane -a "(__complete_crossplane)"

$ crossplane pwsh
Usage: crossplane completions [<shell>] [flags]

Get shell (bash/zsh/fish) completions. You can source this command to get
completions for the login shell. Example: 'source <(crossplane completions)'

Arguments:
  [<shell>]    The shell to install completion for. If not provided, the user's
               login shell will be used.

Flags:
  -h, --help         Show context-sensitive help.
      --verbose      Print verbose logging statements.

      --uninstall

crossplane: error: unsupported shell pwsh

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.

1 participant