Skip to content

completions for aliases #1128

Description

@vilmibm

a user's aliases should be added to tab completions

Activity

  1. added
    coreThis issue is not accepting PRs from outside contributors
    on Oct 7, 2020
  2. rsteube commented on Nov 6, 2020

    @rsteube
    Contributor

    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#L23

    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) {}})
    				}
    			}
    		}
  3. hjdivad commented on Nov 12, 2020

    @hjdivad

    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
  4. lbesnard commented on Jul 1, 2021

    @lbesnard

    @hjdivad

      aliases=$(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)
  5. mislav commented on Aug 12, 2021

    @mislav
    Contributor

    Fixed in #3870

  6. tonglil commented on Nov 4, 2025

    @tonglil

    Was there a regression in this?
    I am not getting tab completions for any aliases.

  7. BagToad commented on Nov 4, 2025

    @BagToad
    Member

    Was there a regression in this?
    I am not getting tab completions for any aliases.

    @tonglil please open a new issue, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLI

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions