mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #92989 from WLun001/fish-completion
add kubectl fish shell completion
This commit is contained in:
commit
cd80d70c3d
@ -44,7 +44,7 @@ const defaultBoilerPlate = `
|
||||
|
||||
var (
|
||||
completionLong = templates.LongDesc(i18n.T(`
|
||||
Output shell completion code for the specified shell (bash or zsh).
|
||||
Output shell completion code for the specified shell (bash, zsh or fish).
|
||||
The shell code must be evaluated to provide interactive
|
||||
completion of kubectl commands. This can be done by sourcing it from
|
||||
the .bash_profile.
|
||||
@ -89,13 +89,20 @@ var (
|
||||
# Load the kubectl completion code for zsh[1] into the current shell
|
||||
source <(kubectl completion zsh)
|
||||
# Set the kubectl completion code for zsh[1] to autoload on startup
|
||||
kubectl completion zsh > "${fpath[1]}/_kubectl"`))
|
||||
kubectl completion zsh > "${fpath[1]}/_kubectl"
|
||||
|
||||
|
||||
# Load the kubectl completion code for fish[2] into the current shell
|
||||
kubectl completion fish | source
|
||||
# To load completions for each session, execute once:
|
||||
kubectl completion fish > ~/.config/fish/completions/kubectl.fish`))
|
||||
)
|
||||
|
||||
var (
|
||||
completionShells = map[string]func(out io.Writer, boilerPlate string, cmd *cobra.Command) error{
|
||||
"bash": runCompletionBash,
|
||||
"zsh": runCompletionZsh,
|
||||
"fish": runCompletionFish,
|
||||
}
|
||||
)
|
||||
|
||||
@ -109,7 +116,7 @@ func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "completion SHELL",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("Output shell completion code for the specified shell (bash or zsh)"),
|
||||
Short: i18n.T("Output shell completion code for the specified shell (bash, zsh or fish)"),
|
||||
Long: completionLong,
|
||||
Example: completionExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
@ -161,3 +168,14 @@ func runCompletionZsh(out io.Writer, boilerPlate string, kubectl *cobra.Command)
|
||||
|
||||
return kubectl.GenZshCompletion(out)
|
||||
}
|
||||
|
||||
func runCompletionFish(out io.Writer, boilerPlate string, kubectl *cobra.Command) error {
|
||||
if len(boilerPlate) == 0 {
|
||||
boilerPlate = defaultBoilerPlate
|
||||
}
|
||||
if _, err := out.Write([]byte(boilerPlate)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return kubectl.GenFishCompletion(out, true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user