How to run a Ruby script in Sublime Text 2 from project root
I have a Ruby project and I'd like to run the scripts directly from Sublime Text in place of having to run them in the terminal. I'm running Ubuntu 12.04 LTS if that matters at all.
From the terminal I need to be located in the project root to make the script work:
$ ruby path/to/file/file.rb
If I try to run it from where the file is located it fails because they are requiring files from various places in the project.
If I run the script in Sublime Text (Ctrl + Shift + B) it fails the same way as I'm running it from the file location.
How do I do this? I suspect this can be solved with a custom build but I've been unsuccessful until now. Any help appreciated.
像这样的构建文件可能会满足您的要求:
{
"working_dir": "/full/path/to/project/root/",
"cmd": ["/full/path/to/ruby/", "$file"],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}
Depending on your scripts you might want to look into using Package Control and the SublimeREPL Package.
SublimeREPL allows you to have a Ruby Interpreter in a separate tab or window in SublimeText. Running CMD + Shift + B has never been very reliable in SublimeText for Ruby code anyways.
Also, similar answer to similar question: Execute Ruby code in sublime text 2
链接地址: http://www.djcxy.com/p/90910.html上一篇: 将插件命令绑定到构建系统?