Contents

Make Bash a little more like home

You may live in the comfort of zsh, and disregard bash as an archaic artefact of the past. You would be sooo wrong… Did you know that with a little bit of tweaking (and reading the doc), bash could do almost all these fancy things you like in zsh?

But why?

Why would you use bash instead of zsh, if you like zsh so much ? I personally have at least two reasons:

  • The first one is for when you don’t have the choice. I use diet-pi as an operating system for my NAS, and diet-pi does not support zsh yet. Bummer! but that’s life…
  • The second one is for when you come to production servers, where installing a new shell for the sole purpose of having a blazing experience seems a little too overkill. In this particular case, having bash behaving a little more like what you use on a daily basis is always good, as it embraces the principle of least astonishment. As more and more people use zsh these days, I consider the following as sane defaults.

Gimme relevant history!

You like it when you begin to type some command, press up arrow, and are served with the last time you used that command? And especially not with the previous command you used, deleting all you just typed? Like if I needed that, a !! would have done the trick…

Here you go: just bind the up arrow to history-search-backward instead of previous-history (source & doc)

In to your Readline init file, a.k.a .inputrc:

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

Alternatively, you can use the bind builtin in your .bashrc:

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

Enable Autocomplete!

Tired of hearing that bell when hitting tab ? Tired of having to type on your keys to choose between options instead of SMASHING THAT TAB KEY EVEN MORE? HERE YOU GO!

Again, in .inputrc

set show-all-if-ambiguous on
TAB:menu-complete
"\e[Z":menu-complete-backward

Or in .bashrc

bind 'TAB:menu-complete'
bind '"\e[Z":menu-complete-backward'
bind 'set show-all-if-ambiguous on'

Tip: use bind -p from the prompt to see all possibilities (and existing shortcuts).

(source & doc)

My extensive config

Here is my sane, very compact and straightforward .inputrc:

❯ cat .inputrc
set show-all-if-ambiguous on
"\e[A": history-search-backward
"\eOA": history-search-backward
"\e[B": history-search-forward
"\eOB": history-search-forward
TAB:menu-complete
"\e[Z":menu-complete-backward

Small config, but I find it so much more enjoyable!

Pimp up that prompt!

Here I will use some external help. zsh has some fancy themes if you install some plugins, but you can also use some cross platform tool to achieve a similar result in bash. Bonus: it works on powershell too! Here comes starship, a dead fast prompt written in rust. it is as easy to install as getting the release from Github and adding a simple line to you .bashrc / .zshrc file.

You can then tune a bit of config to add plugins to show you a lot of information, like the AWS project you’re working on, your git status and the like.

You can even get a transient prompt!

Honorable mentions

ble.sh, if you really miss ZLE so much that you need a bit more, like syntax highlighting or enhanced completions. Beware though, as ble.sh reimplements a lot of builtins (e.g. bind, exit and trap), which may lead to some nasty peculiar issues when scripting/customizing. Test it before install, like this:

git clone --recursive --depth 1 --shallow-submodules https://github.com/akinomyoga/ble.sh.git
make -C ble.sh
source ble.sh/out/ble.sh

oh-my-bash, if you need customization to be as easy as dropping a couple of config lines into a file. It is kind of oh-my-zsh for bash, as the name implies, but it’s way more limited. Cool if you need some completions and don’t want to spend time setting everything up. Beware though, as every form of magic, you may trip yourself with this one. better go with a custom config every_single_time…

That’s All Folks

I hope with this few pieces of advice, your bash feels a little bit more like home :)