feat: support fish shell completion (#1121)

* feat: support fish shell completion

Signed-off-by: Alex Lai <alexlai97@163.com>

* docs: reword

Signed-off-by: Alex Lai <alexlai97@163.com>

* Update cmd/completion.go

Co-authored-by: Shubham Sharma <shubhash@microsoft.com>
Signed-off-by: Alex Lai <alexlai97@outlook.com>
Signed-off-by: Alex Lai <alexlai97@163.com>

* Update cmd/completion.go

Co-authored-by: Shubham Sharma <shubhash@microsoft.com>
Signed-off-by: Alex Lai <alexlai97@outlook.com>
Signed-off-by: Alex Lai <alexlai97@163.com>

* docs: fish completion functions to completions folder

[reference](https://fishshell.com/docs/current/completions.html#where-to-put-completions)

Signed-off-by: Alex Lai <alexlai97@163.com>

Signed-off-by: Alex Lai <alexlai97@163.com>
Signed-off-by: Alex Lai <alexlai97@outlook.com>
Co-authored-by: Shubham Sharma <shubhash@microsoft.com>
Co-authored-by: Alex Lai <laixingyu@cnaeit.com>
This commit is contained in:
Alex Lai 2022-11-07 23:03:10 +08:00 committed by GitHub
parent 0008d46019
commit f51aefb0ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -57,6 +57,12 @@ var completionExample = `
# Set the dapr completion code for zsh[1] to autoload on startup # Set the dapr completion code for zsh[1] to autoload on startup
dapr completion zsh > "${fpath[1]}/_dapr" dapr completion zsh > "${fpath[1]}/_dapr"
# Installing fish completion on Linux
## Load the dapr completion code for fish into the current shell
dapr completion fish | source
# Set the dapr completion code for fish[1] to autoload on startup
dapr completion fish > $HOME/.config/fish/completions/dapr.fish
# Installing powershell completion on Windows # Installing powershell completion on Windows
## Create $PROFILE if it not exists ## Create $PROFILE if it not exists
if (!(Test-Path -Path $PROFILE )){ New-Item -Type File -Path $PROFILE -Force } if (!(Test-Path -Path $PROFILE )){ New-Item -Type File -Path $PROFILE -Force }
@ -77,6 +83,7 @@ func newCompletionCmd() *cobra.Command {
cmd.AddCommand( cmd.AddCommand(
newCompletionBashCmd(), newCompletionBashCmd(),
newCompletionZshCmd(), newCompletionZshCmd(),
newCompletionFishCmd(),
newCompletionPowerShellCmd(), newCompletionPowerShellCmd(),
) )
@ -112,6 +119,19 @@ func newCompletionZshCmd() *cobra.Command {
return cmd return cmd
} }
func newCompletionFishCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "fish",
Short: "Generates fish completion scripts",
Run: func(cmd *cobra.Command, args []string) {
RootCmd.GenFishCompletion(os.Stdout, true)
},
}
cmd.Flags().BoolP("help", "h", false, "Print this help message")
return cmd
}
func newCompletionPowerShellCmd() *cobra.Command { func newCompletionPowerShellCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "powershell", Use: "powershell",