Monday 30 June 2014

sublime text adding custom build

Buid different programs with sublime text:

  Sublime text is one of the best IDE you can think of, using this you can have lots of build functionality to build your code from the IDE at the same time.

What all you have to do:

1. Install sublime text.

2. select "Tools" > "Build System" > "New Build System..."

And over write the:

{
    "shell_cmd": "make"
}

with the following for each of the different language and save them with there own language name at front for your reference. Although you can give what ever name you want.

This will create the file at the following folder:
/home/<user>/.config/sublime-text-3/Packages/User

example for me:
/home/amit/.config/sublime-text-3/Packages/User

3. Following are the config file for each of the language:

3a: For Bash
File name: bash.sublime-build

{
"cmd" : ["$file"],
"selector" : "source.shell",
"shell" : "bash"
}


3b: For mysql
File name: mysql.sublime-build

{
    "cmd": ["mysql", "-u", "root", "-pYourPassword", "-e", "source $file"],
    "file_regex": "sql$",
    "selector": "source.sql"
}


3c: For perl
File name: perl.sublime-build

{
    "cmd": ["perl", "-w", "$file"],
    "file_regex": "pl$",
    "selector": "source.perl"
}



3d: For PHP
File name: php.sublime-build

{
  "cmd": ["php", "$file"],
  "file_regex": "php$",
  "selector": "source.php"
}


On mac for go:
$ pwd
/Users/amund/Library/Application Support/Sublime Text 3/Packages/User
$ cat go.sublime-build
{
    "cmd":["/usr/local/go/bin/go", "run", "$file"],
    "file_regex": "go$",
    "selector": "source.go"
}


4. Few Notes:

  a.You can use ctrl-b to build and can see the output at the IDE.
  b. Other languages are there by default.
  c. I will suggest you to keep in Automatic mode, so that it can use use all the different language at the same time.

5. At the above config: "file_regex": "php$", mean the file end with php, so you might like to save the file with those names and then should try the build.

6. By default the bash script need to be executable permission, before doing the build at the bash script. What I did, I did a directory view of the IDE and created a small bash script that will change the file permission of the files inside a folder and keeping the bash script on those directory. [ chmod -R a+x /home/amit/Documents/bash ] and do a build of this script, when ever I add a bash script at the bash folder.


$ pwd
/home/amit/.config/sublime-text-3/Packages/User
$ l$ ls -1
bash.sublime-build
mysql.sublime-build
perl.sublime-build
php.sublime-build

Preferences.sublime-settings

No comments:

Post a Comment