我想创建Bash一个别名,这样在bash中创建多字别名?
git diff somefile
成为
git diff --color somefile
但我不想这样定义
alias gitd = "git diff --color"
自己的自定义别名,因为如果我习惯了这些自定义别名,然后我放弃了在没有这些映射的机器上工作的能力。
编辑:看来bash不允许使用多字别名。除了创建别名之外,还有其他解决方案吗?围绕分配标志
我想创建Bash一个别名,这样在bash中创建多字别名?
git diff somefile
成为
git diff --color somefile
但我不想这样定义
alias gitd = "git diff --color"
自己的自定义别名,因为如果我习惯了这些自定义别名,然后我放弃了在没有这些映射的机器上工作的能力。
编辑:看来bash不允许使用多字别名。除了创建别名之外,还有其他解决方案吗?围绕分配标志
更好的回答(对于这个特定的情况)。
从git-config
手册页:
color.diff
When set to always, always use colors in patch. When false (or
never), never. When set to true or auto, use colors only when the
output is to the terminal. Defaults to false.
无功能或需要的别名。但是函数包装方法对于任何命令都是通用的;把那张卡片贴在你的袖子上。
再次感谢您指出这一点。我喜欢你的答案。但是这个对我的用例非常具体。所以选择这个作为接受的答案。 – Sudar 2012-04-16 07:17:23
避免坯在bash:
alias gitd="git diff --color"
要为命令创建一个更聪明的别名,你必须写一个具有相同的名称作为命令的封装功能,并分析论证,转换它们,然后用转换后的参数调用真实命令。
例如,您的git
函数可以识别diff
正在被调用,并在那里插入--color
参数。
代码:
# in your ~/.bash_profile
git()
{
if [ $# -gt 0 ] && [ "$1" == "diff" ] ; then
shift
command git diff --color "[email protected]"
else
command git "[email protected]"
fi
}
如果你想diff
之前支持任何选项,仍然有它添加--color
,你必须让这个聪明的分析,很明显。
你在吠叫错误的树。将color.diff
配置选项设置为auto
。
Git有自己的方式来指定别名(http://git-scm.com/book/en/Git-Basics-Tips-and-Tricks#Git-Aliases)。例如:
git config --global alias.d 'diff --color'
然后您可以使用git d
。
我不认为这是可能的... – 2012-04-16 06:34:48