在git中,当我提交更改时,我使用:
git commit -m "my commit message"
我发现每次打字都很耗时,尤其是因为我有一个习惯,就是随着时间的推移进行许多小的提交
我想要一个更容易的别名,例如
gm commit message
我不喜欢在提交消息前后键入引号;gm";比";git commit-m";
在我的.zshrc文件中创建这个别名的最佳方法是什么?
在zsh中:
setopt interactive_comments
preexec(){ _lc=$1; }
alias gm='git commit -m "${_lc#gm }" #'
然后:
gm ** you can use ", ) or any other char's in the commit message
请注意,您的其他别名等可能使用preexec
函数;你可能需要修改它,而不仅仅是覆盖它。
在bash或ksh93中,没有preexec
,但您可以从历史记录中获得当前命令:
alias gm='_lc=$(fc -nl -0); git commit -m "${_lc#*gm }" #'
此外,bash和ksh93在交互脚本中默认识别注释。
gm() { git commit -m "$*" }
gm this works
gm but you need to quote special chars!