我正在尝试为我的代码设置一个 linter,我只想检查当前分支中已更改的咖啡脚本文件。因此,我使用以下命令生成文件列表git
:
git diff --name-only develop | grep coffee$
这给了我一个我想要处理的文件的很好的列表,但我不记得如何将其通过管道传递给 linting 程序来实际完成工作。基本上我想要类似的find
东西-exec
:
find . -name \*.coffee -exec ./node_modules/.bin/coffeelint '{}' \;
谢谢!
答案1
只需通过 while 循环进行管道传输即可:
git diff --name-only develop | grep coffee$ | while IFS= read -r file; do
./node_modules/.bin/coffeelint "$file"
done
答案2
xargs
是我正在寻找的 unix 实用程序。从手册页:
The xargs utility reads space, tab, newline and end-of-file delimited strings from the standard input and executes utility with the strings as arguments. Any arguments specified on the command line are given to utility upon each invocation, followed by some number of the arguments read from the standard input of xargs. The utility is repeatedly executed until standard input is exhausted.
所以,我原来的问题的解决方案是:
git diff --diff-filter=M --name-only develop | grep coffee$ | xargs ./node_modules/.bin/coffeelint