6

I'd like to keep my modifications to as few files as possible, so I don't want to touch .inputrc unless I absolutely have to. So, given .inputrc lines like:

"\e[5~": history-search-backward
"\e[6~": history-search-forward

How can I apply them only using bash?

This SU post indicated that bind could read from .inputrc, and bind's help says:

$ help bind
bind: bind [-lpsvPSVX] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq] [-x keyseq:shell-command] [keyseq:readline-function or readline-command]

history-search-* look like readline functions, so I tried:

bind "\e[6~":history-search-forward
bind "\e[5~":history-search-backward

Page Up now triggers a bell, Page Down printed a ~.

Is there a general way for me to use inputrc lines in bash?

1
  • 2
    One reason to use .inputrc here, though, is so that the key bindings are available in any program that uses readline, not just bash.
    – chepner
    Sep 25, 2015 at 13:43

2 Answers 2

6

According to what I have in my .bashrc you need something like

bind '"\e[6~": history-search-forward'
2
  • ... and now I feel like an idiot. I stopped trying after bind '\e[6~': history-search-forward failed.
    – muru
    Sep 24, 2015 at 6:21
  • 1
    I think I had trouble getting there too, as I noted it as non-obvious in my personal "help on bash" file.
    – meuh
    Sep 24, 2015 at 6:27
6

For anyone else searching, this works for all inputrc commands: just wrap them in quotes, shove a bind in front, and you're good (make sure you have different types of quotes if the actual inputrc command itself requires quotes).


For example, an inputrc could have

# makes tab-completion *immediately* return multiple options, 
set show-all-if-ambiguous on
# bind C-d to go forword, not crush the shell
"\C-d": shell-forward-word

To put those in your bashrc, it's just

bind "set show-all-if-ambiguous on"
bind '"\C-d": shell-forward-word'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.