Pimp your bash!

Let’s start with ~/.inputrc.

This file is used by the Readline library, which is the library used by all Bash shells to control the command line. Add the following to your ~/.inputrc file:

1. history search with up and down arrow keys

"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char

This one is old as dirt. But I am surprised to see so many users without it.

The last two lines aren’t really needed by the MATE Terminal. But they won’t hurt anyways. What they do is avoid you losing the ability to move back and forth with the left and right arrow keys on some terminals.

2. ctrl-right and ctrl-left keys move between words

"\e[1;5D": backward-word
"\e[1;5C": forward-word

This one is gold if you are not an emacs or vi person (see below).

3. single tab for completion; complete the word as far as possible and show remaining possible completions

set show-all-if-ambiguous on

Who here doesn’t hate having to hit tab twice to complete a command or path? I know I do. Now, you just have to hit it once.

4. invoke man page for the command in the current line with alt+h

"\eh": "\C-a\eb\ed\C-y\e#man \C-y\C-m\C-p\C-p\C-a\C-d\C-e"

This one is gold too. I learned it a long time ago – I think on the Arch forums – after asking for something similar on Bash to this out-of-the-box Zsh function.

Note that it doesn’t matter where you are in the line as long as the command was fully typed. Try it after writing cd me into space

5. set editing mode to vi-like keybindings

set editing-mode vi

Readline is a GNU project, so thanks to their ways it uses the emacs keybindings. But you can set it to use vi/vim ones. Nice!

If you use this one, you probably may not want to use 2. above. But if you do, make sure you move it after this one.

6. automatically add sudo to the beginning of the line with alt+s?

"\es":"\C-asudo \C-e"

We all know about sudo !! (don’t we?), but this one is better. Typing a long command and just noticed you forgot sudo? Hitting the home key is not a bad idea. But better is to just hit alt + s and stay on the same spot.

Part 2 is up!

With a bit of .bashrc advise. And it is right here!

13 Likes

FYI: If you set your editing mode to vi, then you must use vi commands in your macros. “\es”:"\C-asudo \C-e" will not work. You need to use “\es”:"\eI sudo " where \e is escape and capital i inserts at the beginning of line. Cheers!