我想創建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