Redirect "git" subcommand to itself?

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Redirect "git" subcommand to itself?

From: Stefan Beller <hidden>
Date: 2016-06-15 23:05:01

Hi,

so I just run into this problem again (which happens to me maybe twice a week):
I want to do a git operations, so I type "git " into my shell, and
then I look around what
exactly I want to do and usually I find it in the help text of a
previous command such as
    You are currently reverting commit 383c14b.
      (fix conflicts and run "git revert --continue")
      (use "git revert --abort" to cancel the revert operation)

then I copy the whole operation "git revert --abort" in this case and
paste it to the shell
and let go.
The result looks like
    $ git git revert --abort
    git: 'git' is not a git command. See 'git --help'.

    Did you mean this?
    init

I wonder if we want to make a "git" subcommand, which behaves exactly
the same as git itself?
Then "git git git status" would just return the same as "git status".

Thanks,
Stefan

Re: Redirect "git" subcommand to itself?

From: Konstantin Khomoutov <hidden>
Date: 2016-06-15 23:05:02

On Wed, 27 May 2015 17:28:34 -0700
Stefan Beller [off-list ref] wrote:
so I just run into this problem again (which happens to me maybe
twice a week): I want to do a git operations, so I type "git " into
my shell,
[...]
then I copy the whole operation "git revert --abort" in this case and
paste it to the shell and let go.
The result looks like
    $ git git revert --abort
    git: 'git' is not a git command. See 'git --help'.
[...]
I wonder if we want to make a "git" subcommand, which behaves exactly
the same as git itself?
Then "git git git status" would just return the same as "git status".
In your ~/.whateverrc, put this:

git() {
  while [ $# -gt 0 ]; do
    test "$1" != "git" && break;
    shift;
  done;
  command git $@;
}

This assumes a POSIX-compatible shell but I think you've got the idea.
("command" is a builtin which forces interpreting the following word as
the name of an external program.)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help