Skip to content

Commit 5e3be64

Browse files
authored
Add Fish shell completion (streamnative#979)
1 parent 737aea3 commit 5e3be64

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

docs/en/enable_completion.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
## Enabling shell autocompletion
2323

24-
pulsarctl provides autocompletion support for Bash and Zsh, which can save you a lot of typing.
24+
pulsarctl provides autocompletion support for Bash, Zsh, and Fish, which can save you a lot of typing.
2525

2626
### Zsh
2727

@@ -94,3 +94,17 @@ pulsarctl completion bash >/usr/local/etc/bash_completion.d/pulsarctl.bash
9494
echo 'source /usr/local/etc/bash_completion.d/pulsarctl.bash' >> ~/.bashrc
9595
source ~/.bashrc
9696
```
97+
98+
### Fish
99+
100+
To load completions once in your current session run:
101+
102+
```bash
103+
pulsarctl completion fish | source
104+
```
105+
106+
To load completions for each session, run:
107+
108+
```bash
109+
pulsarctl completion fish > ~/.config/fish/completions/pulsarctl.fish
110+
```

pkg/ctl/completion/completion.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ rm -f ~/.zcompdump; compinit
6565
},
6666
}
6767

68+
var fishCompletionCmd = &cobra.Command{
69+
Use: "fish",
70+
Short: "Generates Fish completion scripts",
71+
Long: `To load completions run:
72+
73+
pulsarctl completion fish | source
74+
75+
To load completions for each session, run:
76+
77+
pulsarctl completion fish > ~/.config/fish/completions/pulsarctl.fish
78+
`,
79+
RunE: func(cmd *cobra.Command, args []string) error {
80+
return rootCmd.GenFishCompletion(os.Stdout, true)
81+
},
82+
}
83+
6884
cmd := &cobra.Command{
6985
Use: "completion",
7086
Short: "Generates shell completion scripts",
@@ -77,6 +93,7 @@ rm -f ~/.zcompdump; compinit
7793

7894
cmd.AddCommand(bashCompletionCmd)
7995
cmd.AddCommand(zshCompletionCmd)
96+
cmd.AddCommand(fishCompletionCmd)
8097

8198
return cmd
8299
}

0 commit comments

Comments
 (0)