0

Is there any way to add to or wrap an existing command?

For example, if someone runs git pull it really runs git pull --rebase?

Sure, we've written an alias for it, but the issue is that people aren't using the alias.

Is there any way to detect that git pull was run and add to it?

An ideal solution?

$ git pull

echoes out

$ This is not the prefered way of pulling down new code. Did you mean to run ~/my_scripts/git_pull_script.sh?

And then cancels the original git pull.

There's probably a simpler way to do this kind of thing, but searching around hasn't yielded much on adapting existing commands.

1
  • 2
    Is there a directory in everyone's $PATH ahead of the directory that contains git? You could put a git script there that does the extra checks, and then calls the real git. Commented Mar 9, 2022 at 21:14

2 Answers 2

1

To concretise the answer by @Barmar you could write a script like this:

echo $1
if [ "$1" == "pull" ] ;then
    echo This is not the prefered way of pulling down new code. Did you mean to run ~/my_scripts/git_pull_script.sh?
else
    git $*
fi

name it git and place it in a directory, that is in the PATH variable of the users before the actual place of the git binary.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use the command substitution operator $(command) to run a command and capture its output.

For example, if you want to run a command and capture its output, you can use the following:

$(command)

This is useful if you want to run a command and capture its output.

1 Comment

There's nothing in the question about capturing the output of a command. It's about modifying the command itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.