简体   繁体   English

Git预先提交钩子要点

[英]Git pre-commit hook gist

I found this snippet of code https://gist.github.com/wrboyce/786460 我发现了这段代码https://gist.github.com/wrboyce/786460

#!/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

On my osx machine it says: 在我的osx机器上,它说:

.git/hooks/pre-commit: line 2: whence: command not found .git / hooks / pre-commit:第2行:whence:未找到命令

I believe this is for linux only? 我相信这仅适用于linux吗? Could anyone help to do this on a mac? 有人可以在Mac上帮忙吗? I want to minify my css and javascript before it is sent to the remote production server. 在将CSS和javascript发送到远程生产服务器之前,我想使其最小化。

Yes it's for Linux only: 是的,仅适用于Linux:

The whence command is a Korn Shell feature that tells how a name would be interpreted by the shell: it detects commands and aliases, and searches your path. whence命令是Korn Shell程序的功能 ,它告诉外壳程序如何解释名称:它检测命令和别名,并搜索路径。

Try this: 尝试这个:

#!/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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM