bash_execute_unix_command: cannot find keymap for command

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bash_execute_unix_command: cannot find keymap for command

Michał Kazior
Hello,

What I'd like to do is to bind a function to a key sequence (not a
single-byte one - e.g. F1, Arrow Up, etc.).

One would try:

hello() { echo world; }
bind -x '"ab": hello'

The above works if typed "ab". But then:

hello() { echo world; }
bind -x '"abc": hello'

does not and prints (when "abc" is typed):

./script: line 6: bash_execute_unix_command: cannot find keymap for command

I've found anything but an ugly hack [1] as a workaround for this bug.

I'm using "GNU bash, version 4.1.7(2)-release (i686-pc-linux-gnu)" on ArchLinux.

Is this expected? If so, why isn't it stated in the man page? Or am I
missing something?

Thanks in advance. CC me since I'm not subscribed to the list, please.


--
Regards,
Michał Kazior.


[1] http://unix.derkeiler.com/Newsgroups/comp.unix.shell/2003-11/0926.html

Reply | Threaded
Open this post in threaded view
|

Re: bash_execute_unix_command: cannot find keymap for command

Chet Ramey
On 7/4/10 5:14 PM, Michał Kazior wrote:

> Hello,
>
> What I'd like to do is to bind a function to a key sequence (not a
> single-byte one - e.g. F1, Arrow Up, etc.).
>
> One would try:
>
> hello() { echo world; }
> bind -x '"ab": hello'
>
> The above works if typed "ab". But then:
>
> hello() { echo world; }
> bind -x '"abc": hello'
>
> does not and prints (when "abc" is typed):
>
> ./script: line 6: bash_execute_unix_command: cannot find keymap for command

Yeah, this is a problem without a clean solution.

Readline implements multi-character key sequences using a chain of keymaps.
(This is how "ab", "abx", and "abc" can all be bound to different things.)
When it dispatches to the bound function, bash_execute_unix_command here,
the function has access only to the first keymap in the chain and the last.

Bash implements `bind -x' by keeping a parallel set of keymaps holding the
command to be invoked as a macro.  The readline key sequence resolves to
bash_execute_unix_command.

You can see the problem.  For key sequences longer than two characters,
bash_execute_unix_command doesn't have any good way to follow the chain
of keymaps to find the right command.  It knows only the first keymap,
the final keymap, and the key in the final keymap.

There is one good way to fix it, but it requires changing the readline
external interface, which will have to wait until the next major version
is released.  There is probably a clumsy way to do it now, but the code
doesn't implement it.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    [hidden email]    http://cnswww.cns.cwru.edu/~chet/