-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added shell completion command
- Loading branch information
Showing
5 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ tmp-docs/ | |
dist/ | ||
|
||
coverage/ | ||
|
||
completions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
// CompletionCmd generates completion scripts | ||
func CompletionCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "completion [bash|zsh|fish]", | ||
Short: "Print shell autocompletion scripts for multi-gitter", | ||
Long: `To load completions: | ||
Bash: | ||
$ source <(multi-gitter completion bash) | ||
# To load completions for each session, execute once: | ||
Linux: | ||
$ multi-gitter completion bash > /etc/bash_completion.d/multi-gitter | ||
MacOS: | ||
$ multi-gitter completion bash > /usr/local/etc/bash_completion.d/multi-gitter | ||
Zsh: | ||
# If shell completion is not already enabled in your environment you will need | ||
# to enable it. You can execute the following once: | ||
$ echo "autoload -U compinit; compinit" >> ~/.zshrc | ||
# To load completions for each session, execute once: | ||
$ multi-gitter completion zsh > "${fpath[1]}/_multi-gitter" | ||
# You will need to start a new shell for this setup to take effect. | ||
Fish: | ||
$ multi-gitter completion fish | source | ||
# To load completions for each session, execute once: | ||
$ multi-gitter completion fish > ~/.config/fish/completions/multi-gitter.fish | ||
`, | ||
SilenceUsage: true, | ||
DisableFlagsInUseLine: true, | ||
ValidArgs: []string{"bash", "zsh", "fish"}, | ||
Args: cobra.ExactValidArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var err error | ||
switch args[0] { | ||
case "bash": | ||
err = cmd.Root().GenBashCompletion(cmd.OutOrStdout()) | ||
case "zsh": | ||
err = cmd.Root().GenZshCompletion(cmd.OutOrStdout()) | ||
case "fish": | ||
err = cmd.Root().GenFishCompletion(cmd.OutOrStdout(), true) | ||
} | ||
|
||
return err | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
set -e | ||
rm -rf completions | ||
mkdir completions | ||
for sh in bash zsh fish; do | ||
go run main.go completion "$sh" >"completions/multi-gitter.$sh" | ||
done |