14.06.2014 Views

Unix Power Tools

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

30.15<br />

There are two bind options good for use with inputrc type files. To write all the<br />

current key bindings out to a file named inputrc.new, type bind -p><br />

inputrc.new in bash2; use the –d option in original bash. (You can overwrite your<br />

default .inputrc file this way, too, if you want.) To read an inputrc file into the<br />

current shell (if you’ve just edited it, for instance), use bind –f and give the filename<br />

as an argument.<br />

Finally, the bind option –m keymap chooses the keymap that subsequent bindings<br />

apply to. The keymap names that bash2 understands are emacs, emacs-standard,<br />

emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert. (vi is the<br />

same as vi-command, and emacs is the same as emacs-standard.)<br />

zsh Editing<br />

zsh, as you migh expect by now, has a wide variety of command-line editing<br />

capabilities, many similar to or the same as those found in ksh, tcsh, orbash.<br />

Emacs mode is the default, but vi mode may also be chosen, and all of the key<br />

commands found in either mode may be bound to any character you like using<br />

the bindkey –v command. See the zshzle manual page for a long list of these commands<br />

and their default bindings.<br />

—JP and SJC<br />

30.15 Changing History Characters<br />

with histchars<br />

The existence of special characters (particularly !) can be a pain; you may often<br />

need to type commands that have exclamation points in them, and occasionally<br />

need commands with carets (^). These get the C shell confused unless you<br />

“quote” them properly. If you use these special characters often, you can choose<br />

different ones by setting the histchars variable. histchars is a two-character string;<br />

the first character replaces the exclamation point (the “history” character), and<br />

the second character replaces the caret (the “modification” character (30.5)). For<br />

example:<br />

% set histchars='@#'<br />

% ls file*<br />

file1 file2 file3<br />

% @@ Repeat previous command (was !!)<br />

ls file*<br />

file1 file2 file3<br />

% #file#data# Edit previous command (was ^file^data^)<br />

ls data*<br />

data4 data5<br />

zsh’s histchars is like the csh and tcsh version, but it has three characters. The<br />

third is the comment character—by default, #.<br />

Chapter 30: The Use of History 615<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2009 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!