-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completions for aliases #1128
Labels
Projects
Comments
Go this working in my fork by simply adding the aliases as subcommands before the completion generation: func 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) {}})
}
}
} |
FWIW 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 |
Closed
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) |
Fixed in #3870 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
a user's aliases should be added to tab completions
The text was updated successfully, but these errors were encountered: