| 10 | ) |
| 11 | |
| 12 | func NewCmdCompletion(io *iostreams.IOStreams) *cobra.Command { |
| 13 | var shellType string |
| 14 | |
| 15 | cmd := &cobra.Command{ |
| 16 | Use: "completion -s <shell>", |
| 17 | Short: "Generate shell completion scripts", |
| 18 | Long: heredoc.Docf(` |
| 19 | Generate shell completion scripts for GitHub CLI commands. |
| 20 | |
| 21 | When installing GitHub CLI through a package manager, it's possible that |
| 22 | no additional shell configuration is necessary to gain completion support. For |
| 23 | Homebrew, see <https://docs.brew.sh/Shell-Completion> |
| 24 | |
| 25 | If you need to set up completions manually, follow the instructions below. The exact |
| 26 | config file locations might vary based on your system. Make sure to restart your |
| 27 | shell before testing whether completions are working. |
| 28 | |
| 29 | ### bash |
| 30 | |
| 31 | First, ensure that you install %[1]sbash-completion%[1]s using your package manager. |
| 32 | |
| 33 | After, add this to your %[1]s~/.bash_profile%[1]s: |
| 34 | |
| 35 | eval "$(gh completion -s bash)" |
| 36 | |
| 37 | ### zsh |
| 38 | |
| 39 | Generate a %[1]s_gh%[1]s completion script and put it somewhere in your %[1]s$fpath%[1]s: |
| 40 | |
| 41 | gh completion -s zsh > /usr/local/share/zsh/site-functions/_gh |
| 42 | |
| 43 | Ensure that the following is present in your %[1]s~/.zshrc%[1]s: |
| 44 | |
| 45 | autoload -U compinit |
| 46 | compinit -i |
| 47 | |
| 48 | Zsh version 5.7 or later is recommended. |
| 49 | |
| 50 | ### fish |
| 51 | |
| 52 | Generate a %[1]sgh.fish%[1]s completion script: |
| 53 | |
| 54 | gh completion -s fish > ~/.config/fish/completions/gh.fish |
| 55 | |
| 56 | ### PowerShell |
| 57 | |
| 58 | Open your profile script with: |
| 59 | |
| 60 | mkdir -Path (Split-Path -Parent $profile) -ErrorAction SilentlyContinue |
| 61 | notepad $profile |
| 62 | |
| 63 | Add the line and save the file: |
| 64 | |
| 65 | Invoke-Expression -Command $(gh completion -s powershell | Out-String) |
| 66 | `, "`"), |
| 67 | RunE: func(cmd *cobra.Command, args []string) error { |
| 68 | if shellType == "" { |
| 69 | if io.IsStdoutTTY() { |