eljiwo
eljiwo

Reputation: 846

Create alias based on input git commit

I would like to create an alias to be added at the end of my zsh config file that allows me to commit files quickly to git.

Most of the times my commit command would look like:

git commit -m "HO HO HO"

And I was wondering if it is possible to make an alias that would be similar to the previous command but with this syntax:

alias HO HO HO

Where I only call the alias and captures the rest of text on the command as the commit message.

Thanks!

Upvotes: 0

Views: 76

Answers (2)

Vojtech Vitek - golang.cz
Vojtech Vitek - golang.cz

Reputation: 27734

Alternatively, you might set up git alias in your ~/.gitconfig file:

[alias]
    c = "!f() { git commit -a -m \"$*\"; }; f"

Then you can type git c Some commit message.

Upvotes: 0

chepner
chepner

Reputation: 531165

An alias alone cannot do this. The problem is that you want to convert multiple arguments into a single argument for git commit. So you can define a function

foo () {
  git commit -m "$*"
}

and write

foo HO HO HO

However, I don't recommend doing something like this simply to save typing two quotes; provide a single argument yourself. Then you can define an alias

alias foo='git commit -m'

foo "HO HO HO"

Upvotes: 1

Related Questions