在别名中使用其他命令

Using an other command in alias

当此命令为运行时,不是提交命令的时间,而是打印source ~/.zshrc时间。

~/.zshrc:

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

例如

source ~/.zshrc 在 10:00
gitCommitAll 在 10:10 ==> git commit -m "10:00" 不是 10:10

试试这个:

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

双引号 ("") 内的反引号 (``) 将被提前执行。请尝试使用单引号 ('')。

不要使用别名;改用函数。它使引用变得容易得多。像

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

您如何处理函数的参数取决于您希望别名执行的操作。它 看起来 就像你的意思是让所有(或至少第一个)"argument" 成为 -m 选项的一部分,因为一个人的时间并不多提交消息。以上仅将第一个参数作为消息的一部分包含在内。