24.11 Edit Compressed Files with zvi, zex, and zedCompressed files (24.7 ) save disk space. But compressed files aren't as convenient to work with: you have to uncompress them before you can read or edit them. This script makes editing easier. It uncompresses files that were compressed with the GNU gzip utility. Then it starts a text editor: vi , ex , or ed . (It's easy to modify this to use other editors.) The vi and ex editors can edit several files (30.4 ) ; this script handles that. After you edit all the files, the script recompresses them in the background so that you don't have to wait. There's one more bit of trickery here: instead of uncompressing all files you specify before it starts the editor, the script uncompresses just the first file - it does the rest in the background while you're editing the first file. (It figures out what all the uncompressed files will be named. By the time the editor gets to them, they should have been uncompressed.) This makes it easy to save a lot of disk space by keeping your files gzip ped most of the time. The response is almost as fast as editing an uncompressed file, especially if the first file on the command line is a small one. Here's an example. I'll edit the files qlog.gz and /usr/central/data.gz with vi . Next, I'll run zed editing script (28.9 ) on bigfile.gz : %
Most of the script is pretty straightforward. Unfortunately, the script won't work with editors like Emacs (32.1 ) that try to open all files from the command line immediately. You could change that by making the script uncompress all files before starting Emacs. The section that follows is interesting. It's the part that uncompresses background files. If there's an error in the background, how does the script catch it? test -n "$bgfiles" && $uncompress $bgfiles >$t 2>&1 & $prog $files if [ -s $t ] then echo "$myname: 'gunzip $bgfiles' bombed:" 1>&2 cat $t 1>&2 $echo "Should I try to gzip all files [ny](n)? $nnl" read ans The standard output and standard error of the background job goes to a
temporary file, The script is written to have two other links (18.3 ) . You may want to make more or fewer links though, depending on the editors your system has. If you install the script from the CD-ROM, the links will be made for you. If you type in the script, put it in an executable file named zvi . Then make the links: % The script tests the name it was called with, from The absolute pathnames at the start of the script may need to be changed for your system. - |
|