The “bash” shell in TinyCore Linux outputs a “~” when I hit the Delete, Home, or End key

As far as I understand, different command-line interpreters (the Linux console, the bash shell, busybox…) translate these keys (Insert, Delete, Home, End) to key-codes in different ways, and then the underlying programs (aterm, urxvt…) interpret these key-codes with some variations. All of this makes for a rather fragile process. If the terminfo database is up-to-date on your system, this shouldn’t be an issue. However, TinyCore Linux doesn’t seem to even have a terminfo database.

That is why “bash”, or rather the “readline” library that “bash” is using, fails to correctly handle the said keys. But “readline” can be taught.

The “readline” library relies on the /etc/inputrc file, or the ~/.inputrc file, for configuration. So I will create a /home/tc/.inputrc file that will tell “readline” how to handle the above four keys.

First step is knowing what is given to “readline” as input, when said keys are pressed. This is easy to find out: in a terminal, any key is output without being interpreted, as long as you enter Control+V before (press [Control], press [V], release [V], release [Control]). So I will enter these keys in a terminal in this order: Control+V, Insert, Space, Control+V, Delete, Space, Control+V, Home, Space, Control+V, End. Here is the result:

tc@FLASH:~$ ^[[2~ ^[[3~ ^[[7~ ^[[8~

The ^[ combination is actually a single byte meaning Escape, and it is written \e in “readline” syntax. The “readline” man page tells me that the commands to use for my keys are respectively overwrite-mode, delete-char, beginning-of-line, and end-of-line. Thus I create my .inputrc file with the following content:

"\e[2~": overwrite-mode
"\e[3~": delete-char
"\e[7~": beginning-of-line
"\e[8~": end-of-line

Any subsequently opened “bash” shell should behave properly. Now make sure this .inputrc file is saved by TinyCore between reboots.

Ajouter un commentaire

Le code HTML est affiché comme du texte et les adresses web sont automatiquement transformées.

La discussion continue ailleurs

URL de rétrolien : http://yalis.fr/cms/index.php/trackback/16

Fil des commentaires de ce billet