The utility would be:
showkey (1) - examine the codes sent by the keyboard
but this seems to be missing on mac-os...here it is "Key Codes"...?
Or you type ctrl-V (qouted insert) and then some special key. In bash, this prints ^[OP in xterm and ^[[[A in the console for the F1 key.
The readline variable:
keyseq-timeout (500)
is the timeout to use for a half-finished sequence.
Underneath this, there must be a sort of keymap file, where the keys get translated to symbols. This is from /usr/share/kbd/keymaps/mac/ on linux:
keycode 51 = Delete Remove
alt keycode 51 = Meta_Delete
shift alt keycode 51 = Meta_Delete
control keycode 51 = Remove
keycode 53 = Escape
alt keycode 53 = Meta_Escape
shift alt keycode 53 = Meta_Escape
keycode 54 = Control
keycode 55 = Alt # Command/Apple key
keycode 56 = Shift
keycode 57 = Caps_Lock
keycode 58 = AltGr # Alt/Option key
You see the flexibilty! The Meta-Delete symbol could become kill-word...
bind '"^[f": kill-word
This ^[ must be a \e, or a ctrl-V, then Escape: one byte, not circumflex plus bracket.
It is like saying: ^C means control-C, not a Shift-6 and then a Shift-c...in the shell (bash) or in vim when I type ctrl-v and then Esc I get ^[, but it is just one character when you step back over it. Together with these meta-flag options in readline it can get complicated...I just illustrate the whole chain:
keymap "default.map" (translates scancode and modifier to keysymbols)
keycode 105 = Left F150 F151
string F150 = "\033[150"
string F151 = "\033[151"
keycode 106 = Right F154 F155
string F154 = "\033[154"
string F155 = "\033[155"
The F150 and F151 after default "Left" mean shift- and control-left-arrow. In a second step you can define a string, an escape sequence in this case. Here, \e did not work, but the octal 033 is ascii 27 is control-[ is Escape...this keymap is linux specific, but X Windows has a similar logic.
And in .inputrc:
"\e[150": backward-word
"\e[151": shell-backward-word
"\e[154": forward-word
"\e[155": shell-forward-word
This works very nice in the linux console. In xterm under X Windows (Xorg): not at all: Xorg scans the keys itself.
backward-word can be invoked via "\e[150", "\e[1;2D", "\e[1;3D", "\eb".
The two in the middle with semicolon are VTxxx style modified left arrows. This was preconfigured, and also gets bound to backward-word automatically.
fwork? Since (at least on my Linux)\M-fis already bound toforward-word, perhaps that's causing a conflict. – terdon Sep 08 '19 at 11:35bind -q forward-wordresults inforward-word can be invoked via "\e[1;3C", "\e[1;5C", "\ef".– Shuzheng Sep 08 '19 at 11:38\eand\Cas special prefixes? – Shuzheng Sep 08 '19 at 11:39\efisM-f. Does it work if you use another letter? – terdon Sep 08 '19 at 11:42\efis only invoked, if I press the Escape key on the touchbar. Do you know if it's possible to map Option to Escape? And do you know how to control the "timeout", I mention :) ? – Shuzheng Sep 08 '19 at 11:44f. Use Meta and another letter, one that isn't already used anywhere. One of those returned byfor i in {a..z} {A..Z}; do bind -P | grep -q "\"\\\e$i" || echo $i; done. – terdon Sep 08 '19 at 11:49*VT100.metaSendsEscape: true, and then bind your keys as"\ef"instead of"\M-f". See my comments here – Sep 08 '19 at 12:09\e, but it's a pain to press Escape on a Macbook with touchbar. – Shuzheng Sep 08 '19 at 13:02Escape,fto the program inside the terminal when you press Option + F or whatever. Or it can be configured to do that. – Sep 08 '19 at 13:10set keyseq-timeout 10– Sep 08 '19 at 13:18~/.inputrc. or directly in bash withbind 'set keyseq-timeout 10'– Sep 08 '19 at 13:25escape, fwhen pressing Option+F. Or if it doesn't, use another terminal or justbind '"ƒ": ...to whatever your want. – Sep 08 '19 at 13:32bind '"ƒ": kill-word'. Butbind -q kill-wordlists it as"?\222". How can I see thatƒcorresponds to"?\222"? – Shuzheng Sep 08 '19 at 13:47bind -q kill-word | od -c, see that the '?' before\222is octal 306, thenprintf "\306\222\n"will tell you that it really isƒ(yes, this is another bash/readline bug). – Sep 08 '19 at 22:55XXX"experimental code" which still assumes latin1 instead of multibyte/utf-8 and recompile bash, the binding will be printed as"ƒ"instead of"<FROG>\222". You should submit a bug report. – Sep 08 '19 at 23:07\306\222from theƒ(the other direction)? – Shuzheng Sep 09 '19 at 05:15echo ƒ | perl -pe 's/(.)/sprintf"\\%03o",ord$1/ge'– Sep 09 '19 at 06:26