How to print keyboard shortcuts in human-readable form

inputrckeyboard shortcutsreadline

It would be very useful to have a user-friendly way to get an overview of the currently defined keyboard shortcuts. In other words, given the /etc/inputrc lines

"\e[A": history-search-backward
"\e[11~": backward-word

and ~/.inputrc lines

"\e[A": kill-word
"\e\eOD": backward-word

it shouldn't be necessary to go through both files to figure out that \e[A has been overridden, that there are two alternative shortcuts for backward-word, that \e\eOD means … whatever it means, and that kill-word actually means to delete to the end of the current (or next) word. The ideal solution would print something like

Delete until next word boundary: Meta-A
Go to the previous word boundary: F1; Ctrl-Left
Search history backwards: Meta-Up

(Hopefully someone with a better understanding of escape sequences can fix the shortcuts.)

Is there a Linux program to print this?

I'm guessing such a program might be OS, kernel, or even keyboard-dependent, so maybe it would need extensive configuration (a program which polls the user via showkey or xev to press miscellaneous keys to establish which escape sequences are really sent, for example), but that would be an acceptable price to finally understand how to use terminal shortcuts efficiently.

Best Answer

The short answer is no, I'm pretty sure no such program exists.

You could in principle build one; it would have to look at the readline configuration and at the terminal emulator (the kernel and hardware are not involved).

bind -P | grep 'can be found' in Bash lists the key bindings.

abort can be found on "\C-g", "\C-x\C-g", "\e\C-g".
accept-line can be found on "\C-j", "\C-m".

To have a more descriptive name for the command you'd need to parse the bash or readline documentation.

The correspondance between key sequences and keys is determined by the terminal (usually, the terminal emulator). It is often not readily available, and when it is the method to obtain it is entirely specific to the terminal.

You can come close in Emacs: start emacs -q -nw in a terminal, and press Ctrl+H, C (the describe-key-briefly command) then the key sequence (\e is Escape). This shows you the reconstructed function key, if any, and what the key does in Emacs. Readline's default bindings are strongly inspired by Emacs, so often the function in Emacs is similar to the function in readline, but not always. Example:

Ctrl+H C ESC [ A
<up> runs the command previous-line
Related Question