Jan 22, '04 09:59:00AM • Contributed by: folkert
Problem: Cannot enter escape character sequences in terminal inspector
You can add some convenience functions to your shell via a file called .inputrc in your home directory. For example, the line:
"e[5C": forward-wordwill move the cursor to the next whitespace when the character sequence "Escape-[-5-C" is sent to readline by the Terminal (note that ESCAPE is, in fact, a non-printable ASCII character).
Now, you could jump to the next whitespace by pressing the Escape key, the [ key, the 5 key and SHIFT-C key in sequence. As this is not really convenient, Terminal.app allows you to define key bindings. The default setting is to generate the above character sequence when the right arrow key and the Control key are pressed simultaneously. thus, when you press Control-Right on your keyboard, your shell cursor now jumps to the next whitespace. Very convenient (you may have to start a new shell to make it re-read .inputrc).
However, there is a problem in terminal.app: how can you define custom Escape character sequences? For simple, non-Escape character sequences, all you have to do is open Terminal.app's Inspector and push the Add button in the Keyboard view. Set key to cursor right, modifier to control and action to send string to shell. In the textfield, just enter the desired character sequence.
The problem with Escape sequences is that there apparently is no way to enter the Escape non-printable character in this text field. The inspector says to "Hold the option key and press esc or ctrl to create a string containing those special characters." However, pressing Option-Escape does nothing at all, and pressing Option-Escape-[ only generates the unicode character """, like in all Cocoa applications.
So to enter the desired escape character sequence (ESCAPE-[-5-C in this example), you can do the following. In the shell, enter:
echo -ne "e[5C"|pbcopyThis will put the correct escape character sequence in the pasteboard. Just switch to the Inspector again, and paste the pasteboard's content into the textfield. The non-printable escape character will not be visible in the textfield, but will get sent to the shell when the key combination it was bound to is pressed.
Another nice setting is to bind del(forward delete) to Control-D. Strangely enough, pressing Option-Control-D in the Inspector's textfield will generate exactly this character seqeuence (as opposed to the greek delta, which is generated by pressing Option-D in other Cocoa applications).
For further information about shell convenience functions, read the manpage for readline.
[robg adds: I couldn't find a manpage for readline on my machine; the best I could do was any number of web pages with readline man page entries; this one, for instance.]
