Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign syntax to a file without an extension in Sublime Text 2

Tags:

sublimetext2

I have a file Guardfile in my rails project, but appears just in plain text, so each time is opened it must be assigned the ruby syntax to display it correctly.
I cannot use Open all with current extension as... because it doesn't have an extension, but I suppose I could assign a specific syntax to a file without an extension because files like Gemfile, Capfile or Rakefile are displaying correctly. How can I achieve this?

like image 326
Alter Lagos Avatar asked Apr 30 '13 16:04

Alter Lagos


Video Answer


3 Answers

For Sublime 3:

  1. Commmand + Shift + p: set syntax ruby
  2. Preference -> Settings - Syntax Specific
  3. Add syntax like following:

    {
        "extensions": [
            "Gemfile",
            "Gemfile.lock",
            "Podfile",
            "Podfile.lock",
            "Manifest.lock",
            "Fastfile_helper",
            "Fastfile",
            "Appfile"
        ]
    }
    

What really bad is that the syntax does not support fuzzy match, regex thing. This means you must list all the files.

like image 80
ooops Avatar answered Oct 22 '22 20:10

ooops


Menu: Preferences -> Browser Packages

Then open the file Ruby\Ruby.tmLanguage

Look up for this block:

<array>
    <string>rb</string>
    <string>rbx</string>
    <string>rjs</string>
    <string>Rakefile</string>
    <string>rake</string>
    <string>cgi</string>
    <string>fcgi</string>
    <string>gemspec</string>
    <string>irbrc</string>
    <string>capfile</string>
    <string>Gemfile</string>
</array>

Add the new entry:

    <string>Guardfile</string>
like image 36
Hugo Corrá Avatar answered Oct 22 '22 20:10

Hugo Corrá


Install facelessuser / ApplySyntax. It has a built in rule for Guardfiles. It is also good for other random files that should be set as a certain syntax. For example, here is one I set up for a random file that should have Bash syntax.

"syntaxes": [
  {
    "name": "ShellScript/Shell-Unix-Generic",
    "rules": [
      {"file_name": ".*random$"}
    ]
  }
]

The name value is the path to the tmLanguage file from Packages. ShellScript is the name of the Packages folder that the tmLanguage file is in. Shell-Unix-Generic is the tmLanguage file name.

like image 3
d_rail Avatar answered Oct 22 '22 20:10

d_rail