man -w machine

regarding a strange terminal.app behaviour


goalto move the shell cursor around quicker
problemcannot enter escape character sequences in terminal inspector
contextOS X / Terminal.app 1.4.1


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-word

will move the cursor to the next whitespace when the character sequence "ESCAPE-[-5-C" is send to readline by terminal.app. (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 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.apps 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.
now, 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"|pbcopy

this will put the correct escape character sequence in the pasteboard. just switch to the inspector again and paste the pasteboards content in the textfield. the non-printable escape character will not be visible in the textfield, but will get send 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 inspectors textfield will generate exactly this character sequeence [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.


update november 2005:
this behaviour is fixed in Terminal.app v1.5
all rights [r] belong to us.