oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

BBEdit: Its Unix Support Doesn't Suck Either, Part 2

by Kevin O'Malley

Editor's note: In part one of this series, Kevin O'Malley introduced you to BBEdit's Unix support features. Now, in part two, he drills down into filters, scripts, Emacs key bindings, and more.

Unix Filters and Scripts

Worksheets give you lots of options for running shell commands within BBEdit. But they can be somewhat limited. The real power of BBEdit's Unix support comes when you use its Unix Scripting Tools environment.

BBEdit's Unix scripting tools environment is available from the Shebang (#!) menu. If you do not see this menu, open the Preferences window, select the Tools panel, and enable the Unix Scripting Tools checkbox. You will need to restart BBEdit for the menu to appear.

The Shebang menu provides you with all of the hooks to extend the functionally of BBEdit with Unix scripting languages. Before using this feature, let's take a look at BBEdit filters and scripts.

A filter is a program written in a Unix scripting language that operates on any selected text in the foremost BBEdit window. When you run a filter, BBEdit passes the selected text to the filter, runs the specified filter, and overwrites the original text with the output of the filter. Basically, what you are doing is performing a transformation of the selected text, in place.

A script, on the other hand, is more self-contained and does not take selected text as input. A script is a program written in a Unix scripting language that performs some action and writes its output to a BBEdit window called Unix Script Output.

BBEdit filters are located in BBEdit 7.1/BBEdit Support/Unix Support/Unix Filters and scripts are located in BBEdit 7.1/BBEdit Support/Unix Support/Unix Scripts. BBEdit comes with some example filters and scripts for you to play with. To add your own, simply write your filter or script and save it into the right folder. Once you save the file, BBEdit adds it to the appropriate menu -- you do not need to restart BBEdit for the filter or script to be available.

Let's look at the commands that are available from the Shebang menu.

The first menu item is called Check Syntax. You use this command to check the syntax of a Perl script (currently, only Perl scripts are supported). If BBEdit encounters a syntax error while parsing the source file, it displays its "error browser." The error browser provides a convenient interface for displaying errors, enabling you to quickly locate them in your code.

The next menu item is called Run. You use the Run command to execute the script in the foremost window. Once the script is run, BBEdit displays the output of the script in the Unix Script Output window. If you choose to save this window, the file is written to BBEdit 7.1/BBEdit Support/Unix Support.

As you run scripts, BBEdit appends the result of each script to the Unix Script Output window. This is the default action. Remember, it doesn't matter if you run a Perl script followed by a Python script, and then a shell script. In all cases, the output is sent to Unix Script Output.

When you select the Run command, BBEdit executes a script with its default run options. To change the way BBEdit handles running scripts, hold down the Option key as you select the Run command. In this mode, BBEdit displays a dialog box containing the run command options.

The next menu item is called Run in Terminal. This runs the script in the foremost window in a new Terminal window. After the Run in Terminal item is Run in Debugger. Selecting this causes BBEdit to open a new Terminal window and run the script within the languages debugger.

The Run File... menu item permits you to select a file to run, as well as setting BBEdit's run options.

The next menu item is called Find in Reference. This is a very handy command for looking up information on a specific language command. You use the command in one of two ways; the first is to select the command you are interested in from your source file and select Find in Reference. For a Perl script, BBEdit uses the perldoc tool to find the reference and display the result in a new window, titled with the command name. If it's a Python command, BBEdit uses pydoc and displays the result.

If you choose Find in Reference without selecting a command, BBEdit prompts you to enter the text you wish to look up.

The View POD (Plain Old Documentation) is used to view the current window as POD. BBEdit processes the contents of the window with pod2text, and displays it in a new BBEdit window.

The final two menu items contain your saved UNIX filters (Unix Filters) and scripts (Unix Scripts). You can open a filter of script file by holding down the Option key while selecting the filter or script from the menu.

Pages: 1, 2, 3

Next Pagearrow