I'm trying to use Apple's ⌘ command and ⌥ option keys to map some functions in readline to no avail.

As per the man page I used octal values but that doesn't seem to work

\xHH   the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)

For example

# command + j
"\0x37j": "\C-a\C-k"
# option + j
"\0x3aj": "\C-a\C-k"
# control + j
"\0x3bj": "\C-a\C-k"

But octal values don't seem to work for chars on the right side of the mapping either.

# insert char h
"\C-xz": "\0x4"

I know I can use Karabiner, but I'm trying to make this work without third-party applications and to see if it's actually supported or what I'm doing wrong. And I know that in Terminal I can use option mapped to meta, which I don't intend.

  • 2
    Terminals transmit keychords as escape sequences and most terminals don't transmit “exotic” keychords. See unix.stackexchange.com/questions/116629/… and unix.stackexchange.com/questions/244933/… for background. I don't know if OSX Terminal can be configured to send escape sequences for ⌘ and ⌥ modifiers. IIRC iTerm2's mappings can be customized. – Gilles 'SO- stop being evil' Nov 30 '15 at 22:45
  • In Linux the showkey command shows the key codes sent by the terminal. You should look for the OSX equivalent, but as Gilles says some keys don't generate any code and are therefore unusable in terminals. – Ernest A Dec 1 '15 at 9:29
  • @Ernest_A I used script but nothing is retrieved when pressing ⌘. @Gilles, in Terminal's preferences there's indeed the option to send strings with a combination of modifiers and other keys, but not for ⌘ alone. I thought the client is always sending some code and it's the shell that filters it out, but again I have to read the answers you referenced first to make further assumptions. – 1.61803 Dec 2 '15 at 11:21
  • @1.61803 script only shows you what the terminal receives. If the terminal doesn't pass the keystroke through, it doesn't see anything. The shell doesn't filter anything. – Gilles 'SO- stop being evil' Dec 2 '15 at 12:03
  • @Gilles, I read the answers you referenced — so, if the terminal doesn't send the escape sequences for the modifiers, the only solution is a third-party application. Key bindings in Terminal.app are not as flexible as the Cocoa Text System. Eventually I used Karabiner…as always. – 1.61803 Dec 6 '15 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.