2

The Arch Linux Wiki page on Zsh has an example that gets key sequences from terminfo in it.

typeset -g -A key

key[Home]="${terminfo[khome]}"
key[End]="${terminfo[kend]}"
...

But how would I get ones with modifiers? Specifically Alt+j and Alt+k.

Thank you.

4

The ncurses terminal database defines these (see How can I use shift- or control-modifiers? in the ncurses FAQ).

Most of this it's based on work done for xterm (see this page, for example).

Those are unique names (which zsh ignores, since they're not in its dictionary of predefined terminal names — see Src/Modules/terminfo.c). You'd have to make some shell assignment, say, to the output of tput to get the data into a variable.

Alt is typically not considered a modifier when applied to an ordinary key such as j or k in the xterm.

It has a mode (modifyOtherKeys), which can tell it to send an escape sequence for different combinations (see How can my program distinguish control-I from tab? in the xterm FAQ).

In this case, zsh provides no help at all. Likewise, the terminal will not offer a table of the results (it deals with special keys). A customized application would be needed.

You may have in mind the meta feature. That does have a terminfo feature (smm to enable, rmm to disable). However, most terminals (other than xterm) implement this differently from the documented behavior. In terminfo(5):

If the terminal has a "meta key" which acts as a shift key, setting the 8th bit of any character transmitted, this fact can be indicated with km. Otherwise, software will assume that the 8th bit is parity and it will usually be cleared. If strings exist to turn this "meta mode" on and off, they can be given as smm and rmm.

That's partly due to the backwards definition found in bash documentation (see my answer for details). But in any case, terminfo will not hold the information that tells your script what characters might be prefixed with Escape.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.