2012-09-19 35 views
3

我有這樣一個gitconfig:gitconfig走樣不工作(zsh中)

[alias] 
l = "!source ~/.githelpers && pretty_git_log" 

當我運行它,我得到這個:

[desktop] git l 
source ~/.githelpers && pretty_git_log: 1: source: not found 
error: cannot run source ~/.githelpers && pretty_git_log: No such file or directory 
fatal: While expanding alias 'l': 'source ~/.githelpers && pretty_git_log': No such file or directory 

當我添加任何其他殼內置測試,他們運行良好:

[alias] 
l = "!echo running from the builtin" 

[desktop] git l 
running from the builtin 

任何想法爲什麼無法從git中找到源命令?我運行的zsh,但改變抨擊似乎沒有有所作爲:

[desktop] bash 
[desktop] git l 
source ~/.githelpers && pretty_git_log: 1: source: not found 
error: cannot run source ~/.githelpers && pretty_git_log: No such file or directory 
fatal: While expanding alias 'l': 'source ~/.githelpers && pretty_git_log': No such file or directory 
+0

對不起,如果問題是愚蠢的,但爲什麼你需要預先'源'? – CharlesB

+0

這實際上是Gary Bernhardt的gitconfig和.githelpers的一個例子,他有一個名爲pretty_git_log()的函數。我認爲源代碼調用會使命令行中的命令pretty_git_log可用,但不完全確定。 – user1244166

回答

3

失敗來自於這樣!<command>結構試圖通過這個名字來運行找工作這一事實。有一個/bin/echo程序(這是不同於你的外殼內置echo,但這是一個不同的故事),但沒有/bin/source(或/usr/bin或任何其他地方)。根據source的性質,它不能是一個單獨的程序。

試試這個:

[alias] 
l = "!sh -c 'source ~/.githelpers && pretty_git_log'" 

變化shbash(或其他)是必要的。

+0

謝謝,這工作。實際上,我嘗試過使用沒有二進制版本的其他內置版本(我以爲無論如何),而且它們也可以工作,但無論如何,您的示例都可以工作!謝謝。 – user1244166

+0

l =「!bash -c'source〜/ .githelpers && pretty_git_log'」爲我工作,謝謝! – user2167582