Skip to contentSkip to conversation

Using '--help' for aliases

DISCUSSION Kaartic Sivaraam 4 participants 5 messages Jun 21, 2017 – Jun 24, 2017

lore
Share & tools
lore
#0 lore raw

Hello all,

I am yet another user of 'git alias' (who wouldn't ?). It has become so natural to me to use the aliased version that at some point of time I tried the following,

Quoted 2 lines
$ git co --help
`git co' is aliased to `checkout'

That made me wonder. Git is able to inform the user that 'co' is aliased to 'checkout' but isn't it possible for it to take one step more to display help ? Just wondering if there were any reason for not doing it.

Signature · 2 lines
Regards,
Kaartic Sivaraam <[email protected]>
#1 lore raw
Quoted 11 lines · Kaartic Sivaraam

I am yet another user of 'git alias' (who wouldn't ?). It has become so natural to me to use the aliased version that at some point of time I tried the following,

Quoted 2 lines
$ git co --help
`git co' is aliased to `checkout'

That made me wonder. Git is able to inform the user that 'co' is aliased to 'checkout' but isn't it possible for it to take one step more to display help ? Just wondering if there were any reason for not doing it.

It could do that. I think we even discussed it at one point, but I didn't dig up the thread. However, you have the problem that running "man checkout" is likely to clobber the mention of the alias. So the question is whether it is more important to tell the user that it's an alias (and which options the alias is using!), or to show them the referred command's manpage.

-Peff

#2 lore raw
Quoted 7 lines · Jeff King

It could do that. I think we even discussed it at one point, but I
didn't dig up the thread. However, you have the problem that running "man checkout" is likely to clobber the mention of the alias. So the question is whether it is more important to tell the user that it's an
alias (and which options the alias is using!),

Now, that's something I didn't think of. Does seem to quite an issue as aliases accept argument this.

I seem to be getting the idea of '--help' just now. All these days, I was actually considering it to be another way of getting to the man page of a command. Have to play with it a little to see in what other ways '--help' could help me! In case there's anything that's so useful about it that I'm missing, let me know.

Quoted 4 lines

or to show them the
referred command's manpage.

-Peff

Signature · 2 lines
Regards,
Kaartic Sivaraam <[email protected]>
#3 lore raw

You could also just make the alias a bash function that does git help checkout when you pass the --help flag to the alias.

#4 lore raw
In reply to Kaartic Sivaraam
Quoted 11 lines · Kaartic Sivaraam

I am yet another user of 'git alias' (who wouldn't ?). It has become so natural to me to use the aliased version that at some point of time I tried the following,

Quoted 2 lines
$ git co --help
`git co' is aliased to `checkout'

That made me wonder. Git is able to inform the user that 'co' is aliased to 'checkout' but isn't it possible for it to take one step more to display help ? Just wondering if there were any reason for not doing it.

It's possible to do if "co" is an alias for "checkout", but it works less well when co is the following[0]:

	co = "!f() { if git checkout -h | grep -qs recurse-submodules; \
		then git checkout --recurse-submodules \"$@\"; \
		else git checkout \"$@\" && git sui; \
		fi; };f"

If this alias were to run on a Git with that option but without checkout --recurse-submodules, then it would print help and then update submodles, which isn't what I want.

[0] sui is an alias for submodule update --init.

Signature · 3 lines
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204