diff --git a/cmd/talosctl/cmd/completion.go b/cmd/talosctl/cmd/completion.go index 126fcafb3..38b8de505 100644 --- a/cmd/talosctl/cmd/completion.go +++ b/cmd/talosctl/cmd/completion.go @@ -16,8 +16,8 @@ import ( // completionCmd represents the completion command. var completionCmd = &cobra.Command{ Use: "completion SHELL", - Short: "Output shell completion code for the specified shell (bash or zsh)", - Long: `Output shell completion code for the specified shell (bash or zsh). + Short: "Output shell completion code for the specified shell (bash, fish or zsh)", + Long: `Output shell completion code for the specified shell (bash, fish or zsh). The shell code must be evaluated to provide interactive completion of talosctl commands. This can be done by sourcing it from the .bash_profile. @@ -44,11 +44,15 @@ Note for zsh users: [1] zsh completions are only supported in versions of zsh >= source '$HOME/.talos/completion.bash.inc' " >> $HOME/.bash_profile source $HOME/.bash_profile +# Load the talosctl completion code for fish[1] into the current shell + talosctl completion fish | source +# Set the talosctl completion code for fish[1] to autoload on startup + talosctl completion fish > ~/.config/fish/completions/talosctl.fish # Load the talosctl completion code for zsh[1] into the current shell source <(talosctl completion zsh) # Set the talosctl completion code for zsh[1] to autoload on startup -talosctl completion zsh > "${fpath[1]}/_talosctl"`, - ValidArgs: []string{"bash", "zsh"}, + talosctl completion zsh > "${fpath[1]}/_talosctl"`, + ValidArgs: []string{"bash", "fish", "zsh"}, Args: cobra.ExactValidArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { @@ -59,6 +63,8 @@ talosctl completion zsh > "${fpath[1]}/_talosctl"`, switch args[0] { case "bash": return rootCmd.GenBashCompletion(os.Stdout) + case "fish": + return rootCmd.GenFishCompletion(os.Stdout, true) case "zsh": err := rootCmd.GenZshCompletion(os.Stdout) // cobra does not hook the completion, so let's do it manually diff --git a/internal/integration/cli/completion.go b/internal/integration/cli/completion.go index ddb3ba183..b589161bb 100644 --- a/internal/integration/cli/completion.go +++ b/internal/integration/cli/completion.go @@ -24,6 +24,7 @@ func (suite *CompletionSuite) SuiteName() string { // TestSuccess runs comand with success. func (suite *CompletionSuite) TestSuccess() { suite.RunCLI([]string{"completion", "bash"}) + suite.RunCLI([]string{"completion", "fish"}) suite.RunCLI([]string{"completion", "zsh"}) } diff --git a/website/content/docs/v0.14/Reference/cli.md b/website/content/docs/v0.14/Reference/cli.md index afa7b4399..30e90b511 100644 --- a/website/content/docs/v0.14/Reference/cli.md +++ b/website/content/docs/v0.14/Reference/cli.md @@ -253,11 +253,11 @@ A collection of commands for managing local docker-based or QEMU-based clusters ## talosctl completion -Output shell completion code for the specified shell (bash or zsh) +Output shell completion code for the specified shell (bash, fish or zsh) ### Synopsis -Output shell completion code for the specified shell (bash or zsh). +Output shell completion code for the specified shell (bash, fish or zsh). The shell code must be evaluated to provide interactive completion of talosctl commands. This can be done by sourcing it from the .bash_profile. @@ -292,10 +292,14 @@ talosctl completion SHELL [flags] source '$HOME/.talos/completion.bash.inc' " >> $HOME/.bash_profile source $HOME/.bash_profile +# Load the talosctl completion code for fish[1] into the current shell + talosctl completion fish | source +# Set the talosctl completion code for fish[1] to autoload on startup + talosctl completion fish > ~/.config/fish/completions/talosctl.fish # Load the talosctl completion code for zsh[1] into the current shell source <(talosctl completion zsh) # Set the talosctl completion code for zsh[1] to autoload on startup -talosctl completion zsh > "${fpath[1]}/_talosctl" + talosctl completion zsh > "${fpath[1]}/_talosctl" ``` ### Options @@ -2111,7 +2115,7 @@ A CLI for out-of-band management of Kubernetes nodes created by Talos * [talosctl apply-config](#talosctl-apply-config) - Apply a new configuration to a node * [talosctl bootstrap](#talosctl-bootstrap) - Bootstrap the etcd cluster on the specified node. * [talosctl cluster](#talosctl-cluster) - A collection of commands for managing local docker-based or QEMU-based clusters -* [talosctl completion](#talosctl-completion) - Output shell completion code for the specified shell (bash or zsh) +* [talosctl completion](#talosctl-completion) - Output shell completion code for the specified shell (bash, fish or zsh) * [talosctl config](#talosctl-config) - Manage the client configuration file (talosconfig) * [talosctl conformance](#talosctl-conformance) - Run conformance tests * [talosctl containers](#talosctl-containers) - List containers