TarranJones TarranJones - 1 year ago 66
Bash Question

Is extending a shell script by creating a sub-command file unique to git and can it be mimicked for other scripts?

I am aware that

allows you to place a executable file in the
directory which when given the correct naming convention acts as a sub command.

$ git flow

$ git fire

Is this functionality within the git executable or can any executable be overridden by just using this file naming convention.

I have tried this with
$ npm custom
but it executes the
executable rather than
so i'm assuming by default this doesn't work.

If this is implemented through the original command script(
) then can this functionality be reproduced in another way, possible by reading the commands before executing a script.


source ~/.check_for_subcommand_exacutables

Thanks in advance

Answer Source

To do this in general you have to override the precedence of the current git command, which should be easy unless you've already done it in some way. For example, you can create a function which falls back to the original command by default:

git() {
    case "$2" in
            command "$@"

In the case of Git specifically, you can create aliases for subcommands, such as st = status

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download