Steve Kehlet
Steve Kehlet

Reputation: 6426

How to force Intellij to highlight file with no extension as Bash?

I'm editing Linux init.d scripts with Intellij IDEA 12 Ultimate and would like it to use Bash syntax highlighting. I already have the Bash syntax highlighting plugin, and it works great for files ending in .sh. The problem with the init.d scripts is they have no extension, and it seems the only way to get Intellij to recognize a files type (Preferences -> File Types -> Registered Patterns) is by extension. If Registered Pattern supported paths (like */etc/rc.d/init.d/*) that would be swell, but that doesn't seem to work.

The only workaround I've found for now is to add the name of each script I want to edit to Registered Patterns. Better than nothing, but does is there a better way? Thanks!

Upvotes: 35

Views: 12951

Answers (7)

Trey Edwards
Trey Edwards

Reputation: 51

UPDATE for anyone stumbling across this issue.

As of the latest version (2018.2.6), Intellij comes with an "Associate with File Type" for files without an extension. Just right-click on the file in projects and if the file has no extension this option should be available as the second option under new. Just don't click too fast as the associate option disappears once your selection is made.

Found this trying to figure out how to associate JS files without an extension.

Upvotes: 5

Rickard
Rickard

Reputation: 1299

The easiest way to do this:

  • Install the BashSupport plugin for IntelliJ
  • Right click the file you want highlighted
  • Choose "Associate with filetype"
  • Select "Bourne Again Shell"

All similar files will be recognized as bash.

Upvotes: 9

Trevor Mack
Trevor Mack

Reputation: 155

If you happen to have previously registered a file with IntelliJ (ex. when you initially create the file) that the file should be interpreted as Text this would add your file to the default mapping for Text in preferences. If you intend to create a file as Bourne Again Shell (aka bash) then at this point just tell IntelliJ that is what you intend. Otherwise you will need to manually go and remove these custom mappings from preferences before these files will show up for Bourne Again Shell. Preferences - Editor - File Types - Text

Upvotes: 10

Matt Savage
Matt Savage

Reputation: 347

The BashSupport plugin will work, but it doesn't cope with spaces after the shebang.

#!/usr/bin/env bash

not

#! /usr/bin/env bash

Upvotes: 3

agim
agim

Reputation: 1841

To make IntelliJ recognize a file without extension [i.e. install] as a bash file:

  1. Create a file install.bash - after creating IntelliJ will recognize both files, install & install.bash as bash files
  2. Now delete the install.bash file.
  3. The file install remains marked as a bash file.

This worked for me (IntelliJ Idea 15), even after restarting IntelliJ all files were marked as bash files..

Update for IntelliJ 2016:

Adding the shebang line #!/usr/bin/env bash makes idea recognize the files without the .sh extension as well

Upvotes: 5

InfoSponge
InfoSponge

Reputation: 114

For anyone else stumbling across this older question, the BashSupport plugin for IntelliJ will do this out of the box.

Upvotes: 1

Eugene Evdokimov
Eugene Evdokimov

Reputation: 2545

You can use the *. pattern. Though it's registered for Text files type by default.

Upvotes: 20

Related Questions