(免责声明:我之前发布了一个类似的问题: In a ruby script, how to ask git to open its message editor.我决定将此作为一个单独的问题发布,因为我认为这个问题更通用,因此可能更适用于其他程序员
我目前正在开发一个命令行ruby gem,它可以自动化在https://gist.github.com/jbenet/ee6c9ac48068889b0912讨论的“rebase no-ff merge”工作流程.你可以在https://github.com/gsmendoza/git_pretty_accept/tree/git_pretty_accept找到这个gem的WIP代码.gem会做这样的事情:
`vi some_temp_file.txt` `git co master` `git pull` `git co pull_request` `git rebase master` `git co master` merge_message = File.read('some_temp_file.txt') `git merge --message "#{merge_message}" --no-ff pull_request` `git push` `git branch -d pull_request` `git push origin:pull_request`
当我尝试通过ruby运行这些git命令时,vi some_temp_file.txt不会像我希望的那样打开文本编辑器.相反,我看到一个警告“Vim:警告:输出不是终端”,脚本只是挂起.
有任何想法吗?
要从ruby脚本中运行bash命令,可以使用system()命令:http://www.ruby-doc.org/core-2.0.0/Kernel.html#method-i-system
这应该在您的特定情况下产生所需的行为:
#!/usr/bin/ruby system('vim', 'some_temp_file.txt')
从命令行运行此脚本将在Vim中打开给定文件.