I have two shell scripts I use regularly as git
CLI shortcuts:
push
#! /bin/bash
git push "$@"
commit
#! /bin/bash
git add --all && git commit "$@"
I use them like this:
$ touch foo
$ commit # type in a message in the editor
$ push --force-with-lease
I’d like to make push
tab and commit
tab autocomplete as though I typed git push
tab and git commit
tab, respectively.
Here’s what I’ve learned/tried:
- This post shows how to give a shell script the same auto completion as another command, but it doesn’t work for git subcommands. For example, I could make
commit
tab behave likegit
but notgit <subcommand>
. - This post shows how to make a git command autocomplete with custom behavior. For example, I could make
git p
tab autocomplete likegit push
tab, but it wouldn’t work forcommit
: I’m not using a git command, merely a regular command, and I prefer to keep it that way.
Is there a way to make a shell script autocomplete like a specific git subcommand?
I am using bash and git-completion.bash
is sourced in my shell’s startup script. I’m using cygwin on Windows 10, if that makes a difference.
6