Несвязанные ключи в ReadLine

354
porton

Об использовании Readline с Bash:

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

Теперь в терминале Gnome F11 и F12 ключевые истории поиска назад / вперед.

Но если я случайно нажму, скажем, F10, он издает звуковой сигнал и добавляет тильду. Я хочу, чтобы он не добавлял тильду (я не уверен, должен ли он подавать звуковой сигнал или ничего не делать).

Пожалуйста, помогите мне сделать все несвязанные ключи не такими глупыми, как вставка тильды.

2

2 ответа на вопрос

1
harrymc

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" 
Я бы предпочел сделать это с самой readline. porton 8 лет назад 0
readline работает в gnome-терминале. harrymc 8 лет назад 0
Но я хочу, чтобы он работал и в других терминалах, таких как Konsole. porton 8 лет назад 0
Вышесказанное применимо в теории для всех приложений gtk-3, и я добавил эквивалент для приложений gtk-2. Нет гарантии, что это будет работать для * всех * терминальных приложений. Вы должны закрыть все окна терминала, чтобы эти изменения вступили в силу. harrymc 8 лет назад 1
1
Clueless Guest

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.