forked from toolshed/abra
.gitea
cli
app
catalogue
internal
recipe
server
updater
complete.go
run.go
upgrade.go
cmd
pkg
scripts
tests
vendor
.dockerignore
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var AutocompleteCommand = &cobra.Command{
|
|
Use: "autocomplete [bash|zsh|fish|powershell]",
|
|
Short: "Generate autocompletion script",
|
|
Long: `To load completions:
|
|
|
|
Bash:
|
|
|
|
$ source <(abra autocomplete bash)
|
|
|
|
# To load autocompletion for each session, execute once:
|
|
# Linux:
|
|
$ abra autocomplete bash > /etc/bash_completion.d/abra
|
|
# macOS:
|
|
$ abra autocomplete bash > $(brew --prefix)/etc/bash_completion.d/abra
|
|
|
|
Zsh:
|
|
|
|
# If shell autocompletion 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 autocompletions for each session, execute once:
|
|
$ abra autocomplete zsh > "${fpath[1]}/_abra"
|
|
|
|
# You will need to start a new shell for this setup to take effect.
|
|
|
|
fish:
|
|
|
|
$ abra autocomplete fish | source
|
|
|
|
# To load autocompletions for each session, execute once:
|
|
$ abra autocomplete fish > ~/.config/fish/completions/abra.fish
|
|
|
|
PowerShell:
|
|
|
|
PS> abra autocomplete powershell | Out-String | Invoke-Expression
|
|
|
|
# To load autocompletions for every new session, run:
|
|
PS> abra autocomplete powershell > abra.ps1
|
|
# and source this file from your PowerShell profile.`,
|
|
DisableFlagsInUseLine: true,
|
|
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
|
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
switch args[0] {
|
|
case "bash":
|
|
cmd.Root().GenBashCompletion(os.Stdout)
|
|
case "zsh":
|
|
cmd.Root().GenZshCompletion(os.Stdout)
|
|
case "fish":
|
|
cmd.Root().GenFishCompletion(os.Stdout, true)
|
|
case "powershell":
|
|
cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
|
|
}
|
|
},
|
|
}
|