0

What is the best way to obtain a two-way dictionary between a specific key (specified by either a descriptive name or by the press of a the corresponding key) to a code like \e[7~ as used in .inputrc and vice versa.

I have read https://superuser.com/a/269471/728074 but it doesn't help much. Not only would it be cumbersome to have to look in the output of either infocmp -L -1 or infocmp -L -1 xterm for any key specified in .inputrc but it doesn't even seem to contain the ones I find in my .inputrc file. For example the key "\e[7~" found in .inputrc is not found anywhere in the output of those commands. Nor are the other examples given in both that question and answer.

I have also read https://unix.stackexchange.com/questions/76566/where-do-i-find-a-list-of-terminal-key-codes-to-remap-shortcuts-in-bash, but running sed -n l and then for example the home key reveals a different key than the .inputrc file suggests I should find.


sed -n l

followed by the home key and enter gives:

^[[H
\033[H$
Kvothe
  • 101
  • 6

1 Answers1

0

The answer you linked to is very comprehensive and correct.

Basically ^[[H and \033[H are exactly the same sequence, just different representation of the same character: 033 octal is the binary code for Ctrl+[.

The first line is the local terminal echo from the terminal device, while the second line is output by sed (excluding the $).

This shouldn't be specified differently anywhere else.

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • So these can be used interchangeably or wil `.inputrc` require one or the other format? If they can be used interchangeably it does clarify one direction of the directory. It still isn't clear how to easily find out what key a given code corresponds to. Note that neither form can be found in the outputs of the `infocmp` command. – Kvothe Aug 24 '21 at 19:20
  • The other answers in your second link contain some good pointers, for example [this one](https://unix.stackexchange.com/a/611800/17660). – harrymc Aug 24 '21 at 19:26