bug-bash
[Top][All Lists]
Advanced

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

Re: readline: How to unbind _all_ keys


From: Dennis Williamson
Subject: Re: readline: How to unbind _all_ keys
Date: Tue, 21 May 2019 16:33:38 -0500

On Tue, May 21, 2019 at 3:04 AM Henning <xaoxx@t-online.de> wrote:

> On 20/05/2019 15:38, Chet Ramey wrote:
> > On 5/19/19 10:43 AM, Henning wrote:
> >> I don't like to have dozens of key bindings I never use. Currently I
> >> am issuing lots of lots of bind -r/-u commands to get rid of the
> >> default bindings. This slows down console startup unnecessarily.
> >>
> >> I would really like to have an inputrc command like $removeall or
> >> something like bind -r/-u all.
> >> Or is there something undocumented for this purpose?
> >
> > There is not, and I don't see much point to adding one. If you want to
> > remove the bindings for all keys, something like this should work:
>
> Sorry, the subject of my mail should have been "... all non-self-insert
> kes.
>
> >
> > for ((f=0; f < 256; f++ ))
> > do
> >       bind -r \\$(printf "%03o" $f)
> > done
> >
>
> smiling ...
>
> The following variant does what I want:
>
>         K=( ' ' ! '\"' \# $ % \& \' \( \) \*  +   ,   -  .  /
>              0  1   2   3 4 5  6  7  8  9  : \;  \<   = \> \?
>              @  A   B   C D E  F  G  H  I  J  K   L   M  N  O
>              P  Q   R   S T U  V  W  X  Y  Z \[ '\\' \]  ^  _
>             \`  a   b   c d e  f  g  h  i  j  k   l   m  n  o
>              p  q   r   s t u  v  w  x  y  z \{  \|  \} \~     )
>
>         for ((k=0; k<95; k++)); do
>             bind -r "\e${K[k]}"
>             bind -r "\e\C-${K[k]}"
>             bind -r "\C-x\C-${K[k]}"
>             bind -r "\C-x${K[k]}"
>             bind -r "\C-${K[k]}"
>         done
>
>         for k in O{A,B,C,D,H,F} \\e [200; do
>             bind -r "\e$k"
>         done
>
>         bind -f /0/e/inputrc
>
>         unset k K
>
> But this means nearly 500 bind -r commands. And that was the reason for
> my original mail, the question, if there is a less expensive way to get
> what I want.
>
> And another problem: after removing all \C-x sequences I used bind -x
> to bind a shell command to \C-x proper. The result, when hitting \C-x,
> is the following error message:
>
>         bash_execute_unix_command: cannot find keymap for command
>
> Using a sequence other than \C-x works as expected.
> My guess is that \C-x can't be used alone. And that this can only be
> changed in the source code.
>
> Henning
>
>
>
Why don't you unbind the keystrokes that are actually bound?

while read -r b; do bind -r "$b"; done < <(bind -p | awk -F ':' '/./
&& !/self-insert|accept-line|^#/ {gsub("\"", "", $1); print $1}')

On my system, that takes 0.011 seconds to run and it's not iterating
through a bunch of key sequences that aren't there.

It does seem to leave behind a few, some of which match cchars (control
characters) in stty -a

"\C-?": backward-delete-char
"\C-v": quoted-insert
"\C-@": set-mark
"\e ": set-mark
"\C-u": unix-line-discard
"\C-w": unix-word-rubout

I haven't made any effort to troubleshoot that.

As an alternative, just put all the (un)bindings in ~/.inputrc, for example:

"\C-s": ""

To automate that:

bind -p | awk -F ':' '/./ && !/self-insert|accept-line|^#/ {print $1 ":
\"\""}' >> ~/.inputrc

Run that once from a shell with all the default bindings in place, edit the
file to remove any that conflict with your own custom bindings and you're
done. There will still be a small shell startup time cost, but I'm betting
it's very small.

Frankly, I'd have to dislike key bindings A LOT to go to the trouble of
doing all this unbinding.

> But I can not remove bindings with key-sequences my terminal does not
produce like \eO[ABCDFH]

But then you show a script that purports to do exactly that.

This inquiry would have been better suited for help-bash rather than
bug-bash.

-- 
Visit serverfault.com to get your system administration questions answered.


reply via email to

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