Project36.Edit with GUI-Based Editors


Project 36. Edit with GUI-Based Editors

"Can I use 'normal' editors, with mouse clicks and menus, to edit configuration files and write shell scripts?"

This project takes a brief look at using graphical editors that run in the Mac OS X Aqua environment. It touches on Apple's TextEdit and on TextWranglera free editor from Bare Bones Software.

Configure Your Editor

It's perfectly acceptable to use a graphical-based text editor to write code and shell scripts, and to edit Unix configuration files. There's one drawback, though: Your Unix colleagues may mock you for not "doing it the Unix way".

Keep It Plain

If you use an OS X text editor, there is one golden rule you must follow: Make sure your files are saved as plain text. Word processors and Rich Text editors embed unwanted font and formatting information in files. Also, choose a fixed-width font so that columns align correctly, and choose a face in which the letters l and O (ell and oh) are clearly distinguishable from the digits 1 and 0.

Line Breaks

Watch out for line-break characters. Traditional Macintosh editors use a carriage return (CR, ASCII character code 13) to break lines. Unix requires a line feed (LF, ASCII character code 10). If your editor has an appropriate option or preference, make sure it is set to write Unix line feeds.

If you find yourself with text files that contain Mac-style line breaks, the contents of those files will appear to Unix commands to be one long line. A simple way to fix this is to use the command tr, which translates a file containing CR breaks into one with LF breaks.

$ tr '\r' '\n' < mac-file > unix-file


Note

Old mechanical typewriters required both a carriage return, which moved the carriage back to its start position on completion of a line, and a line feed to move the paper up. Microsoft Windows requires both, too.


Edit as Root

System configuration files are writable only by root. You'll find it more difficult to edit such files in a graphical editor. Some editors, such as TextWrangler (discussed later in this project), recognize this situation and will ask you to authenticate to modify the file.

TextEdit

Apple's TextEdit application can be used to edit Unix files. If you ensure that the file is plain text (Figure 4.5), TextEdit will write Unix LF characters automatically when the file is saved.

Figure 4.5. Choose Format > Make Plain Text in TextEdit if you're working on Unix files.


Learn More

Project 6 gives some more examples of using the tr command.


Learn More

See "How to Become the Root User" in Project 2.


If you try to edit an HTML file with TextEdit, you'll find the program suffering an identity crisis: It suddenly becomes a browser. It will let you edit displayed text, but it won't show you the HTML tags in the file. As a clunky workaround, open the file you want to edit in Safari, and choose Source > View Source. Copy the HTML text that's displayed, and paste it in to a new plain-text TextEdit file.

TextWrangler

TextWrangler (Figure 4.6) is an excellent programmer's editor, available as a free download from the Bare Bones Software web site, (www.barebones.com).

Figure 4.6. TextWrangler, the free text editor from Bare Bones Software, is a Mac OS X application that's outstanding for editing Unix files.


As a programmer's editor, TextWrangler has some powerful features, such as:

  • Support for Unix and Mac end-of-line formatting.

  • Syntax coloring for a variety of programming languages, including Unix shell scripts, Perl, HTML, and PHP.

  • Autoindenting.

  • Multi-file search and replace with regular-expression matching. (Projects 77 and 78 cover regular expressions.)

  • Multiple clipboards.

  • File difference and merging. (Projects 24 and 25 feature Unix file-difference and merging tools.)

  • Remote file access via FTP (File Transfer Protocol) and SFTP (Secure File Transfer Protocol), enabling you to edit files on a remote machine.




Mac OS X UNIX 101 Byte-Sized Projects
Mac OS X Unix 101 Byte-Sized Projects
ISBN: 0321374118
EAN: 2147483647
Year: 2003
Pages: 153
Authors: Adrian Mayo

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net