简体   繁体   中英

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.

A build file like this might meet your requirements:

{
  "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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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