zhuxiaoxi
zhuxiaoxi

Reputation: 153

Using an other command in alias

When this command is run, it is not the time to submit the command, But print the source ~/.zshrc time.

~/.zshrc:

alias gitCommitAll="git add . && git commit -m \"`date +\"%T\"`\""

eg.

source ~/.zshrc at 10:00
gitCommitAll at 10:10 ==> git commit -m "10:00" not 10:10

Upvotes: 2

Views: 136

Answers (2)

chepner
chepner

Reputation: 531055

Don't use an alias; use a function instead. It makes quoting far easier. Something like

gitCommitAll () {
  git add . && git commit -m "$(date +%T) $1"
}

How you handle the argument(s) to the function depend on what you intended the alias to do. It looks like you meant for all (or at least the first) "argument" to be part of the -m option, as a time alone isn't much of a commit message. The above just includes the first argument as part of the message.

Upvotes: 2

Packard CPW
Packard CPW

Reputation: 339

Try this:

alias gitCommitAll='git add . && git commit -m "`date +%T`"'

Backquote (``) inside double quotes ("") will be executed prematurely. Try using single quotes ('') instead.

Upvotes: 2

Related Questions