Wednesday, April 17, 2019

bash - separate mappings for TAB and C-i in .inputrc


For what I have tried, "TAB" and "C-i" in .inputrc seems to mean the same thing, whatever I bind to one is bound to the other. I know that originally, it was the same thing and that this behavior is kind of inherited from the old times but nowadays, apart from terminal emulators, all X applications makes the difference between a C-i and a TAB press.


So is there a way to run a terminal command ("complete" for example) when I press the TAB key and run another command when I press "C-i"?


(the same question applies for C-m and ENTER, C-z, C-d, and all these control sequences that I would like to send by other means than their original binding and apply my own commands to these precious keybindings)


And by the way, if you could explain a little bit the process from a keypress to a shell interpretation that would help me understand. For now I understood that keyboard events are translated by Xmodmap, then by .inputrc and that the result is interpreted by the shell or something like this.


Answer



There is no direct connection between xmodmap and .inputrc.


There are a few ways, depending on the terminal emulator, for modifying the keys sent via the terminal. Some of those include



  • modifying the X keyboard configuration (xkb)

  • modifying the keycodes sent for a given event (xmodmap)

  • terminal-specific things such as the translations resource used by xterm.


However, in the normal situation, control/I sends a tab character because that is the way almost all terminals were setup.


With xkb, you can (in principle) change what the keyboard does. In turn, the X applications detect key press and release events, and translate those into key symbols. xev is useful for showing events. A terminal emulator running in X gets the series of events, which (using X library calls) it can translate into characters. A tab is just another character in that case.


xmodmap's role in that process would be as an ad hoc change to the X keyboard configuration.


If you happen to be using xterm, the translations resource gives a lot of configurability. That is a feature of the X Toolkit, which allows you to associate various key combinations with xterm's built-in actions. The default key bindings are listed in the manual. You can override or add to those bindings. There are several places where you can set the information ($HOME/.Xdefaults for example, though it can get cluttered easily). For example, I set the XAPPLRESDIR environment variable to point to my user directory which contains customized app-defaults files. In one named XTerm, I could put this to change the result of ctrl/I:


*VT100*translations:    #override \n\
Ctrl ~ShiftI:string("??")

Because the tab key has its own special key-symbol, it is not affected by this translation.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...