Repository navigation
completions for aliases #1128
Copy link
Copy link
Closed
Labels
coreThis issue is not accepting PRs from outside contributorsThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIa request to improve CLI
Description
Activity
- addedcoreThis issue is not accepting PRs from outside contributorsThis issue is not accepting PRs from outside contributors
on Oct 7, 2020 Go this working in my fork by simply adding the aliases as subcommands before the completion generation:
https://github.com/rsteube/gh/blob/master/pkg/cmdutil/completion.go#L23func Aliases() (map[string]string, error) { if config, err := config.ParseDefaultConfig(); err != nil { return nil, errors.New("failed to parse DefaultConfig:" + err.Error()) } else { if aliasCfg, err := config.Aliases(); err != nil { return nil, errors.New("failed to load AliasCfg:" + err.Error()) } else { aliases := make(map[string]string) for key, value := range aliasCfg.All() { aliases[key] = value } return aliases, nil } } } c.PreRun = func(cmd *cobra.Command, args []string) { if aliases, err := action.Aliases(); err == nil { for key, value := range aliases { cmd.Root().AddCommand(&cobra.Command{Use: key, Short: value, Run: func(cmd *cobra.Command, args []string) {}}) } } }
Reacted by Mislav Marohnić, Alfonso Montero López and Shoichi AizawaFWIW a very simple bash script to wrap the existing completion:
#!/usr/bin/env bash _gh_completion_with_aliases() { # if gh call super and add extra # assumes gh completion has already been sourced __start_gh aliases=$(gh alias list | cut -d: -f 1) matching_aliases=$(compgen -W "$aliases" "${COMP_WORDS[1]}") COMPREPLY+=($matching_aliases) } complete -F _gh_completion_with_aliases gh
Reacted by Mislav Marohnić, Alfonso Montero López and Shoichi Aizawaaliases=$(gh alias list | cut -d: -f 1)this is only good if aliases are one liner. Something along these lines is working better (but not perfect)
$(gh alias list | grep -o -e '^[a-z].*:' | cut -d : -f1)Reacted by David J. HamiltonFixed in #3870
Was there a regression in this?
I am not getting tab completions for any aliases.Was there a regression in this?
I am not getting tab completions for any aliases.@tonglil please open a new issue, thank you!
Metadata
Metadata
Assignees
Labels
coreThis issue is not accepting PRs from outside contributorsThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIa request to improve CLI
a user's aliases should be added to tab completions