forked from toolshed/abra
		
	
		
			
				
	
	
		
			66 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package cli
 | |
| 
 | |
| import (
 | |
| 	"os"
 | |
| 
 | |
| 	"coopcloud.tech/abra/pkg/i18n"
 | |
| 	"github.com/spf13/cobra"
 | |
| )
 | |
| 
 | |
| var AutocompleteCommand = &cobra.Command{
 | |
| 	// translators: `autocomplete` command
 | |
| 	Use:   i18n.G("autocomplete [bash|zsh|fish|powershell]"),
 | |
| 	// translators: Short description for `autocomplete` command
 | |
| 	Short: i18n.G("Generate autocompletion script"),
 | |
| 	Long: i18n.G(`To load completions:
 | |
| 
 | |
| Bash:
 | |
|   # Load autocompletion for the current Bash session
 | |
|   $ source <(abra autocomplete bash)
 | |
| 
 | |
|   # To load autocompletion for each session, execute once:
 | |
|   # Linux:
 | |
|   $ abra autocomplete bash | sudo tee /etc/bash_completion.d/abra
 | |
|   # macOS:
 | |
|   $ abra autocomplete bash | sudo tee $(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)
 | |
| 		}
 | |
| 	},
 | |
| }
 |