5

I have a number of shell scripts - written in PHP - within a project. None of these files have a file extension and cannot have one added due to constraints caused by legacy code. Currently within Netbeans there doesn't appear to be a way to make these scripts be identified as PHP and thereforce use the syntax highlighting of other PHP scripts. Common methods in different editors to allow shell scripts to make use of syntax highlighting are through things like modelines in Vim (other examples here) but as far as i can tell there is nothing similar in Netbeans. Each file has a shebang and php tags that both identify the scripts as being php files. Does anyone know a workaround for this? I'm willing to add content to the files to make this work but for a number of reasons i cannot add an extension.

FWIW i'm using the PHP version of netbeans 6.9.1 with the C/C++ plugin to enable syntax highlighting of .sh files

2 Answers 2

11

I accomplished it by right-clicking the file and selecting the "Open As..." option. In the dialog window then select the "text/x-php5" option and click the "Open" button.

Interestingly enough, when I go to "Tools" > "Options", "Miscellaneous" section, "Files" tab, I don't see a way to remove or change associations made for files without extensions from there.

After additional digging I found the file that holds the definitions. On Windows XP it can be found here:
[%HOMEDRIVE%%HOMEPATH%]\.netbeans\6.9\config\Services\MIMEResolver\user-defined-mime-resolver.xml

My file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MIME-resolver PUBLIC "-//NetBeans//DTD MIME Resolver 1.1//EN" "http://www.netbeans.org/dtds/mime-resolver-1_1.dtd">
<MIME-resolver>
    <file>
        <ext name=""/>
        <resolver mime="text/x-php5"/>
    </file>
</MIME-resolver>
Sign up to request clarification or add additional context in comments.

2 Comments

can't believe i've not noticed that option before - although this isnt doing any kind of actual filetype detection it basically works since 99% of my files without extensions are PHP files anyway. Thanks!
You're welcome! To be fair, the option only shows for files that don't have a MIME Resolver set up already.
-1

Do the files have a .php extension? Syntax highlighting should be automatic if you're using the PHP version. (By the way, the PHP version is just the core with PHP extensions installed.)

2 Comments

Sorry I mis-read... thought you meant you couldn't add an extension to Netbeans. As far as I'm aware, adding a PHP extension is the only solution. Would you mind explaining why you can't add the PHP extension? There might be another solution.
The issue is that there is a massive amount of legacy code which calls these shell scripts that cannot be touched. Altering the filename simply is not an option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.