macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

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

by Kevin O'Malley
04/27/2004

Editor's note -- This first article of a two-part series introduces you to BBEdit's Unix support features. If your background is Macintosh development, you will learn how to take advantage of these features and incorporate them into your development process. If you are a Unix developer coming to Mac OS X, you will learn how to carry over your development techniques using Mac OS X tools. Some of the topics are not strictly Unix-based features, but are still quite interesting and useful. Part 2 will run on Friday, April 30.

I'm not sure when it happened, but somewhere along the line, I became a real fan of text editors. Maybe it's because I spend most of my day writing code. I learned early that a good editor will make the development process a lot more productive and more importantly, more enjoyable. Aside from coding, I use a text editor for most of my writing needs; from articles to project documentation. As you've read in my other articles, I'm not a big fan of word processors.

Macintosh programmers have never had the hardcore devotion to their editors that Unix developers have. This is probably because Macintosh development has traditionally centered on an Integrated Development Environment (IDE) and not a command-line development style, where you pick and choose your tools.

Unix, on the other hand, has always offered a more segregated development environment where you are free, in effect, to create your own development environment. For most Unix developers this means writing code in their favorite editor and building and running programs from the command line. In this style of development, you are far freer to mix and match tools and usually converge on a set that you use for all of your development needs. The centerpiece is the text editor.

In fact, it's not uncommon for a Unix developer or user to open an Emacs session in the morning and stay in it all day. Within Emacs they write code, compose and read email, read news (Usenet), open and use a shell, and view their calendar.


(Click for larger view)

Most Macintosh developers have not grown up with the notion that their editor is a powerful, multi-use tool. Something, in effect, that serves many uses and is extendable to many problem domains. For example, one of the reasons I've always liked Emacs is its stability, features, and expendability. With Emacs, you can open a shell within a buffer, edit remote files using Ange ftp, and extend the editor's functionally with Elisp. In addition, the language modes are a great selling point for using the editor for all your writing needs.

Related Reading

Mac OS X Panther for Unix Geeks
Apple Developer Connection Recommended Title
By Brian Jepson, Ernest E. Rothman

So, what I am looking for in a Mac OS X editor is the stability, features, and expendability of Unix editors like Emacs, but wrapped in a well-designed Aqua GUI. An editor that I can use for all my writing needs; from code development to general writing tasks. Also, Unix support is high on my list. By Unix support I mean how well the editor enables me to incorporate Unix tools and development techniques into its environment.

The good news is that you can get these features in BBEdit for Mac OS X. BBEdit is a rock-solid editor that offers many useful features and contains some very good support for accessing Unix commands, tools, and scripting languages.

BBEdit, Some Background

BBEdit (Bare Bones Text Editor) was created by Rich Siegel, and began its life when he was at THINK in 1989. Originally, BBEdit was released as a freeware product in 1991. The first commercial version of BBEdit (2.5) was released May 11, 1993. The first native Mac OS X release was version (6.1), which was released April 20, 2001. If you are interested, the complete history is available from the Bare Bones web site.

BBEdit has a long history within the Macintosh development and user communities. Over the years it has been used for many different editing tasks, including application development, general writing, and editing web site content. Recently, its HTML tools have been a major focus, but at its heart, it's still a very solid text editor.

The thing that you will immediately appreciate about BBEdit is that it's a very well made, solid product. It has a clean, well-thought-out interface and its features always work as advertised. Basically, it just feels right.

Getting and Installing BBEdit

In this article, we will use the latest version of BBEdit, version 7.1.3. If you do not own a copy, you can download a demo of this version from the Bare Bones web site. After downloading the demo, simply follow the installation instructions that come with the program. The BBEdit demo is not crippled in any way, but it will expire after 30 days.

Once you install BBEdit, you need to set some configuration options. Locate the BBEdit demo and launch the program. The first time you run BBEdit, you are asked if you wish to install the bbedit tool. Installing this tool permits you to run BBEdit from the command line, something you want to do. Say yes to this option so that the tool is installed.

Next, select BBEdit --> Preferences to display the preferences window. There are lots of options here, but we will only focus on those that are relevant to this article. See the BBEdit user manual for more information on all the options.

If you are an Emacs user, you will happy to learn that BBEdit offers a setting called "Use Emacs Key Bindings." This option enables partial Emacs key bindings for editing. To use this option, select the "Text Editing" panel and click on the "Use Emacs Key Bindings" checkbox.

A related setting is "Display Status Window," which causes BBEdit to display a floating window with the name of the last Emacs command you typed.

If you plan on sharing files between the Unix and Mac OS X environments, you should set the default line breaks mode to Unix. You set this by selecting the "Text Files: Savings" panel and selecting the Unix radio button, under the "Default Line Breaks" section.

Finally, select the Tools panel. This panel holds options that control what development tools you can access within BBEdit. Under the "Coding Tools" section, make sure "Unix Scripting Tools" is set. This will enable you to interact with Unix scripting tools like Perl, Python, and Shell within BBEdit.

The "Default Shell" popup menu, located at the bottom of the window, permits you to select your favorite shell. You will see how this is used later, but for now, just select the shell you use from the command line. If you are not sure what shell you use, select /bin/tcsh.

Finally, you want to make sure you can run BBEdit from the command line. To do this, you need to install the bbedit tool. As you saw, the first time you run BBEdit, it asks if you want to install the tool. If you have not already done so, click on the "Install bbedit Tool" button.

That's it for the basics. At this point, you may want to take a few minutes to explore the other preference settings. There are lots of other options you may want to know about.

Command Line Interaction

BBEdit supports command-line operation through the bbedit tool. This program lets you interact with BBEdit from the command line, and supports some very useful options. In addition to opening and creating files, you can also pipe stdin to the bbedit tool, which lets you use BBEdit with Unix pipes.

To open an existing file from the command line, open a shell and type the following command:

% bbedit [file-to-open]

To create a new file from the command line, you use the -c option. This will create a new file and open it in BBEdit:

% bbedit -c [file-to-create]

You can also use the bbedit tool with Unix pipes. For example, you can open a set of Python files with the following command:

% find . -name "*.py" | xargs bbedit

The bbedit tool supports lots of other useful options. For example, "+<line number>" enables you to open a file within BBEdit and place the cursor at a specified line number, just like Emacs. The following command opens the file .cshrc and moves the cursor to line 100:

% bbedit +100 .cshrc

Finally, the p option will print the listed file, or files, to your default printer. To get more information on the bbedit tool, see its man page (man bbedit) or type "bbedit -h" at the command prompt.

Pages: 1, 2

Next Pagearrow