2

About using Readline with Bash:

$ cat ~/.inputrc 
"\C-[[Z": complete-command
"\C-[[23~": history-search-backward
"\C-[[24~": history-search-forward

Now in Gnome terminal F11 and F12 key search history backward/forward.

But if I incidentally press say F10, it beeps and adds tilde. I want it not to add tilde (I am unsure whether it should beep or do nothing).

Please help me to make all unbound keys not to do nonsense like inserting tilde.

2 Answers 2

1
+50

As far as I can tell, there is no way to set a value for "all keys" in .inputrc. But realistically, that's not really required in your use case; there are only so many keys you can hit by accident.

Personally, I've been using an .inputrc originally derived from some very old SUSE release, but it has continued to work perfectly, even after copying it over to various other installs and distros. This file has explicit "nothing" mappings for function keys that are not currently used by readline:

#
# Function keys F1 - F12
#
$if term=linux
#
# On console the first five function keys
#
"\e[[A":    prefix-meta
"\e[[B":    undo
"\e[[C":    ""
"\e[[D":    kill-line
"\e[[E":    ""
$else
#
# The first five standard function keys
#
"\e[11~":   prefix-meta
"\e[12~":   undo
"\e[13~":   ""
"\e[14~":   kill-line
"\e[15~":   ""
$endif
"\e[17~":   ""
"\e[18~":   ""
"\e[19~":   ""
"\e[20~":   ""
"\e[21~":   ""
# Note: F11, F12 are identical with Shift_F1 and Shift_F2
"\e[23~":   ""
"\e[24~":   ""

where \e[17~ corresponds to F6, and so on.

Mapping the unused function keys to "" should prevent the beep and the tilde, no matter which desktop environment you're using. I think your best bet is to identify the keys you tend to hit accidentally and assign them to "" in your .inputrc.

You can disable the terminal bell with set bell-style none, also in your .inputrc.

1

For gtk-3 apps like gnome-terminal and nautilus, try this : Create (or edit) the file ~/.config/gtk-3.0/gtk.css with the following content:

$ cat ~/.config/gtk-3.0/gtk.css
@binding-set NoKeyboardNavigation {
unbind "F10"
}

* {
gtk-key-bindings: NoKeyboardNavigation
}

For gtk-2 apps add this in ~/.gtkrc-2.0 :

binding "NoKeyboardNavigation" {
        unbind "F10"
}

class * binding "NoKeyboardNavigation"
4
  • I would prefer to do this with readline itself.
    – porton
    Commented Dec 13, 2015 at 18:07
  • readline works in gnome-terminal.
    – harrymc
    Commented Dec 15, 2015 at 7:53
  • But I want it to work in other terminals such as Konsole too
    – porton
    Commented Dec 15, 2015 at 18:46
  • 1
    The above applies in theory for all gtk-3 apps, and I added the equivalent for gtk-2 apps. There is no guarantee that this will work for all terminal apps. You have to close all terminal windows before these changes may take effect
    – harrymc
    Commented Dec 15, 2015 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .