MCPcopy Create free account
hub / github.com/dotzero/git-profile / Completion

Function Completion

cmd/completion.go:10–63  ·  view source on GitHub ↗

Completion returns `completion` command

(rootCmd *cobra.Command)

Source from the content-addressed store, hash-verified

8
9// Completion returns `completion` command
10func Completion(rootCmd *cobra.Command) *cobra.Command {
11 return &cobra.Command{
12 Use: "completion [bash|zsh|fish|powershell]",
13 Short: "Generate shell completion script",
14 Long: `Generate shell completion script for Git Profile.
15
16To load completions:
17
18Bash:
19
20 $ source <(git-profile completion bash)
21
22 # To load completions for each session, execute once:
23 # Linux:
24 $ git-profile completion bash > /etc/bash_completion.d/git-profile
25 # macOS:
26 $ git-profile completion bash > $(brew --prefix)/etc/bash_completion.d/git-profile
27
28Zsh:
29
30 # Create completion directory and generate file:
31 $ mkdir -p ~/.zsh/completions
32 $ git-profile completion zsh > ~/.zsh/completions/_git-profile
33
34 # Add to ~/.zshrc if not already present:
35 $ echo 'fpath=(~/.zsh/completions $fpath)' >> ~/.zshrc
36 $ echo 'autoload -U compinit && compinit' >> ~/.zshrc
37
38 # Reload shell or run: source ~/.zshrc
39
40Fish:
41
42 $ git-profile completion fish | source
43
44 # To load completions for each session, execute once:
45 $ git-profile completion fish > ~/.config/fish/completions/git-profile.fish
46`,
47 ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
48 Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
49 DisableFlagsInUseLine: true,
50 Run: func(_ *cobra.Command, args []string) {
51 switch args[0] {
52 case "bash":
53 _ = rootCmd.GenBashCompletionV2(os.Stdout, true)
54 case "zsh":
55 _ = rootCmd.GenZshCompletion(os.Stdout)
56 case "fish":
57 _ = rootCmd.GenFishCompletion(os.Stdout, true)
58 case "powershell":
59 _ = rootCmd.GenPowerShellCompletionWithDesc(os.Stdout)
60 }
61 },
62 }
63}

Callers 1

initMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected