Github: https://github.com/fritx/jayin/tree/cn
假如你有一个类似于 gitignore 的文件:
# .gitignore
*
!.gitignore
!README.md
!prs-welcome.svg
!.bashrc
!.bash_profile
!.exports
!.aliases
!.editorconfig
你想要 cp 这些文件到另外一个文件夹。
用 bash 来搞?
files=$(cat .gitignore | sed /^\*$/d | sed s/\!//)
for file in $files; do cp $file ./dotfiles/; done
# or even
cat file | sed /^\*$/d | sed s/\!// \
| while read -r file; do cp $file ./dotfiles/; done
瓦特?
作为一名 node.js 工程师,为什么不能用 js 流来处理呢?
cat .gitignore | js -ti 'x.trim().split(`\n`).slice(1).map(x => x.slice(1))' \
| js -e 'exec(`cp ${x} ./dotfiles/`)'
# same as
cat .gitignore | js -ti 'x.trim().split(`\n`)' \
| js 'x.slice(1)' \
| js 'x.map(x => x.slice(1))' \
| js -e 'exec(`cp ${x} ./dotfiles/`)'
不要忘了搞一个 alias ,如果你需要的话。
npm install -g jayin
alias js="jayin"
-ti
: 以文本的形式直接 input ,无需 JSON.parse-to
: 以文本的形式直接 output ,无需 JSON.stringify-t
: 以上两者-e
: for eachx
: 当前的 input 内容i
: current index value (with -e)exec(cmd)
: child_process.execSync(cmd)jayin 基于through2.
如果你发现已经早已有类似的东西存在,不妨告诉我一下 ;)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.