2014-01-22 47 views
0

我發現的代碼https://gist.github.com/wrboyce/786460Git的pre-commit鉤子要點

#!/usr/bin/zsh 

COMPRESSOR=$(whence -p yui-compressor) 
[ -z $COMPRESSOR ] && exit 0; 

function _compress { 
     local fname=$1:t 
     local dest_path=$1:h 
     local min_fname="$dest_path/${fname:r}.min.${fname:e}" 
     $COMPRESSOR $1 > $min_fname 
     git add $min_fname 
} 

for file in $(find . -regextype posix-extended -iregex '.+\.(css|js)$' -and -not -iregex '.+\.min\.(css|js)$'); _compress $file 

這個片段在我的OSX的機器,它說:

的.git /掛鉤/預提交:線路2:何處:命令沒有找到

我相信這隻適用於linux?任何人都可以幫助在Mac上做到這一點?在發送到遠程生產服務器之前,我想縮小我的css和javascript。

回答

1

是它是僅適用於Linux:

在何處命令是Korn Shell程序功能告訴你如何名稱 將由外殼程序解釋:它檢測到的命令和別名, 和搜索您的路徑。

試試這個:

#!/usr/bin/zsh 

COMPRESSOR=$(which yui-compressor) 
[ -z $COMPRESSOR ] && exit 0; 

function _compress { 
     local fname=$1:t 
     local dest_path=$1:h 
     local min_fname="$dest_path/${fname:r}.min.${fname:e}" 
     $COMPRESSOR $1 > $min_fname 
     git add $min_fname 
} 

for file in $(find . -regextype posix-extended -iregex '.+\.(css|js)$' -and -not -iregex '.+\.min\.(css|js)$'); _compress $file 
+0

阿涼,讓我試試,謝謝 – Harry

+0

奇怪,那裏也是一個內置的zsh。我實際上是在我的OSX機器上寫下了原始的要點。 –