mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +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 (
|
var (
|
||||||
completionLong = templates.LongDesc(i18n.T(`
|
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
|
The shell code must be evaluated to provide interactive
|
||||||
completion of kubectl commands. This can be done by sourcing it from
|
completion of kubectl commands. This can be done by sourcing it from
|
||||||
the .bash_profile.
|
the .bash_profile.
|
||||||
@ -89,13 +89,20 @@ var (
|
|||||||
# Load the kubectl completion code for zsh[1] into the current shell
|
# Load the kubectl completion code for zsh[1] into the current shell
|
||||||
source <(kubectl completion zsh)
|
source <(kubectl completion zsh)
|
||||||
# Set the kubectl completion code for zsh[1] to autoload on startup
|
# 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 (
|
var (
|
||||||
completionShells = map[string]func(out io.Writer, boilerPlate string, cmd *cobra.Command) error{
|
completionShells = map[string]func(out io.Writer, boilerPlate string, cmd *cobra.Command) error{
|
||||||
"bash": runCompletionBash,
|
"bash": runCompletionBash,
|
||||||
"zsh": runCompletionZsh,
|
"zsh": runCompletionZsh,
|
||||||
|
"fish": runCompletionFish,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -109,7 +116,7 @@ func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "completion SHELL",
|
Use: "completion SHELL",
|
||||||
DisableFlagsInUseLine: true,
|
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,
|
Long: completionLong,
|
||||||
Example: completionExample,
|
Example: completionExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
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)
|
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