cli icon indicating copy to clipboard operation
cli copied to clipboard

Support aliases deeper than top level, e.g. `gh pr co`

Open issyl0 opened this issue 5 years ago • 8 comments

Describe the feature or problem you’d like to solve

I type gh pr checkout many times a day. Typing checkout is long. I have shell aliases for git checkout: gco. That muscle memory could carry over to gh pr checkout too, with the gh pr co command alias.

I'd like to think that this affects many people using gh pr checkout: not just me. But I've not done any research to verify that thought.

Proposed solution

Add an alias for co to the pr_checkout command.

I considered some alternatives, like the existing tab completions. While they do work as intended, gh pr c<tab><tab> and gh pr ch<tab> take three keypresses, and are different from the "usual" co abbreviation for checkout.

I've got the change ready to go locally - but as per the contributing guide, I'm submitting an issue first to see if there's an appetite for this!

Additional context

Thanks for building the gh tool!

issyl0 avatar Jul 01 '20 08:07 issyl0

Hi, thanks for explaining how you're using gh!

Would it be an option for you to create a gh alias for pr checkout? E.g.

$ gh alias set co 'pr checkout'
$ gh co 123

In fact, I believe that we ship with this alias as default for new users who are installing GitHub CLI.

mislav avatar Jul 01 '20 10:07 mislav

gh alias set co 'pr checkout' works - thanks, @mislav. I didn't realise alias set was a thing. 😳

I did try out gh alias set 'pr co' 'pr checkout', which doesn't seem to work. But I understand that keeping the pr namespacing is perhaps not the preferred way (even though it makes more sense to me as co operates on PRs in this case).

issyl0 avatar Jul 01 '20 11:07 issyl0

@issyl0 You're right, right now aliases are only supported at "top-level" and not nested under a command such as pr. We could potentially support nested ones too, but I don't see why someone would create a 2-word alias when they can create a 1-word one.

Do you feel that this can be closed or that we should keep it open as a feature request?

mislav avatar Jul 01 '20 13:07 mislav

Thanks for your responses. This is fine to close. If gh co still seems weird in a week or two, I can keep my local change to support gh pr co.

issyl0 avatar Jul 01 '20 14:07 issyl0

Same here. In my usage case, I've tried to define gh issue mine as issue list --author pataquets. Ended up implementing it as issue.mine, but supporting deeper aliases would open some meaningful shortcuts for common switches as described. @mislav: I would like to ask this issue to be left open to keep track of it, in case sometime in the future it could be implemented, although I understand it might not be a priority now.

pataquets avatar Feb 23 '21 16:02 pataquets

That's a good point! Reopening

mislav avatar Feb 23 '21 19:02 mislav

The same here. I was trying to add gh pr browse for pr view -w like we have gh browse.

mathieutu avatar Apr 19 '22 16:04 mathieutu

Just wanted to drop my use-case in this issue (I didn't see it when I opened my own!).

I have gh go aliased to gh repo view --web, but I'd like to extend that to other commands (e.g. gh pr go for gh pr view --web). I could do something like gh prgo (one word) but it's more natural to me to think of go = view --web.

cravend avatar Jun 21 '22 10:06 cravend