help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Passing argument to a function defined with 'bind -x'


From: Jesper Nygårds
Subject: Passing argument to a function defined with 'bind -x'
Date: Fri, 23 Apr 2021 17:38:17 +0200

I have a function that I have bound to <alt-a> with 'bind -x'". I would
like to be able to pass some simple argument or state to the called
function, so that it could behave differently depending on this state. In
zsh, if you call such a function after pressing the key for numeric
argument (i.e. pressing alt-<number>) , what I think is call digit-argument
in bash, that numeric argument is passed to the corresponding function.

This is a simple version of what I would like to use:

_insert_message() {
    if [[ -n $NUMERIC ]]; then
        READLINE_LINE+="yes"
    else
        READLINE_LINE+="no"
    fi
}
bind -x '"\ea":_insert_message'

However, I got stuck even more quickly than I expected. If I press the keys
<alt-2><alt-a> in succession, I get the following error: "bash:
bash_execute_unix_command: cannot find keymap for command".

So I have two questions:
- Why does the above error occur?
- Is there a way to pass an argument to a function bound with "bind -x"?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]