Some notes on computer stuff code tags rss about

Making ~/.inputrc work in slackware

October 13, 2012
[issue] [bash] [inputrc] [gnu/linux] [slackware]

Today I accidentally trapped on this part of Arch Linux wiki page on Bash. And decided to try putting set show-all-if-ambiguous On to my ~/.inputrc, which was created for this.

So I did it, but didn't see any change in newly started instances of Bash. Then I found a C-X C-R mapping somewhere on StackOverflow and decided to try loading my ~/.inputrc to running instance of Bash, but still had no luck.

I also found ~/.inputrc_ file, which was a result of my tries to make Arrow Up and Arrow Down keys work like in Vim's command line: recall only commands that start with already typed command beginning:

"\e[A": history-search-backward
"\e[B": history-search-forward
"\eOA": history-search-backward
"\eOB": history-search-forward

This time I was going to make it work, no matter what it takes :-) So I did the thing that should have been done long before: read man readline. Here's what I've found:

Readline is customized by putting commands in an initialization file
(the  inputrc  file).  The name of this file is taken from the value
of the INPUTRC environment variable.  If that variable is unset, the
default  is  ~/.inputrc.   If that file  does not exist or cannot be
read, the ultimate default is /etc/inputrc.

Obviously, the next thing what to see if $INPUTRC is defined:

[~]$ echo $INPUTRC
/etc/inputrc

But I didn't set it! Lets find out who did this:

[~]$ grep -R INPUTRC= /etc 2>/dev/null
/etc/profile:  export INPUTRC=/etc/inputrc
/etc/zprofile:  export INPUTRC=/etc/inputrc
/etc/profile~:  export INPUTRC=/etc/inputrc

Finally, the reason was found:

[~]$ sed -n '11,14p' /etc/profile
# If the user doesn't have a .inputrc, use the one in /etc.
if [ ! -r "$HOME/.inputrc" ]; then
  export INPUTRC=/etc/inputrc
fi

Lest make a conclusion. If you logged in when there is no ~/.inputrc file, you can try hard to make it work with no result. It's hard to say why someone wants to have such behaviour. Anyway, at least we know the reason now and can fix it by login out and back in, by setting $INPUTRC to $HOME/.inputrc in ~/.bashrc:

export INPUTRC="$HOME/.inputrc"

or by unsetting it there:

unset INPUTRC

If you want to test in immediately from the shell there are several options you may try:

  • Unsetting $INPUTRC and reloading init-file of readline by pressing C-X C-R.

This won't work. C-X C-R actually reloads init-file, which was remembered during initialization process. So we need something different.

  • Unsetting $INPUTRC and running another Bash instance.

This one should work.

  • Running Bash instance unsetting $INPUTRC variable for that subprocess only.

Not sure if this is useful, but if it works why not give it a try? This requeres running of Bash using env:

env -u INPUTRC bash
  • Empty $INPUTRC is counted as nonexistend, so running Bash this way will work too:
INPUTRC= bash
  • This one is the last. Almost the same as second and forth options:
INPUTRC=
bash