Enhanced Bash

The first thing I do when I install a new Linux on my machine is updating .inputrc and .bashrc files to support “Enhanced Bash”. These improves might look minor at first glance, but they had improved my experience with the shell very much.

The main features you achieve by enabling “Enhanced Bash” are:

1. Easily match previously typed commands from partial input. Doing this is as easy as typing the beginning of the command and hitting page up/down to scroll through history.

2. Share history between terminals: When you close a terminal you don’t lose the command history.

3. Let grep highlight matched words with a different color. Very useful.

To enable these features, open your ~/.inputrc file and type this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# -------- Bind page up/down wih history search ---------
"\e[5~": history-search-backward
"\e[6~": history-search-forward
# -------- more sane command matching --------------------
#do not show hidden files in the list
set match-hidden-files off
#removes the annoying "-- more --" prompt for long lists
set page-completions off
#show the "Display all 123 possibilities? (y or n)" prompt
# only for really long lists
set completion-query-items 350
# show the list at first TAB, instead of beeping and
# waiting for a second TAB to do that
# uncomment next line to enable
#set show-all-if-ambiguous on

And append these to ~/.bashrc

1
2
3
4
5
6
7
8
#Make sure all terminals save history
shopt -s histappend
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
#Increase history size
export HISTSIZE=1000
export HISTFILESIZE=1000
#Use GREP color features by default
export GREP_OPTIONS='--color=auto'


You can learn more about this in the original post in Ubuntu Wiki

Hope somebody will find this useful :)

If you enjoyed this post, make sure you subscribe to my RSS feed!

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

No related posts.

Tags: , ,

Friday, January 30th, 2009 Bash

17 Comments to Enhanced Bash

  • David says:

    set show-all-if-ambiguous on

    ahhh!

    Finally solved – why I have to double-tab in Fedora
    but only single-tab complete (preferred) in Mandriva

  • Paul says:

    Using Kubuntu 8.10. There is no .inputrc file in my home directory.

  • Christian says:

    Hi, I get this errormessage byy the .inputrc:

    bash: e[5~:: command not found
    bash: e[6~:: command not found

  • Tom says:

    I get the same errormessage. Using Ubuntu 8.10, maybe the entire ~/.inputrc thing is not supported in this distro? (had to create the file myself)

  • Christian says:

    Actually the .inputrc made me loose the ability to use “s” in bash, really anoying, worked anywhere else and got corrected when I removed the .inputrc-file entirely.

  • Amir Watad says:

    Hi,
    For anybody who couldn’t get this work, can you email me your .inputrc file?
    Amir DOT Watad AT gmail DOT com

  • Christian says:

    E-mail sent.

  • Bjarke Bruun says:

    The inputrc file is a global file located in /etc aka /etc/intpurc – you need to be root to edit it. It is also where you can disable the annoying bell sound by uncommenting the

    set bell-style none

  • Amir Watad says:

    Hi Bjarke,
    Thank you for your comment.
    Indeed, there is the /etc/inputrc file, and it’s similar to ~/.inputrc, except that it’s a system wide file (i.e. affects all users, and this is why you need root privileges to edit it).
    ~/.inputrc is a per user file, and I prefer to edit it and not the system wide file (except if you have a reason to make changes for all users).

    Sometimes ~/.inputrc is not found by default, and you need to create it.

    Please notice that ~/.inputrc and /etc/inputrc are NOT bash scripts, so please don’t try to source them (i.e. by typing source .inputrc or . .inputrc etc..), you’ll get errors from the simple reason that you’re trying to run a non-script file.

    Thanks again for your comments

  • Brett says:

    To everyone getting a “command not found” error when sourcing the .bashrc or .inputrc, this most likely a copy and paste error.
    Make sure the single quote “‘” (which bash will interpret as the start of a string) is not getting converted to a backtick “`” (which bash will interpret as “execute inline”, causing the commond not found error).
    Also if your home dir does not have a .inputrc in it just create the file, relogin and bash will load those settings for you.
    Thanks Amir, great tips

  • Amir Watad says:

    Thank you Bret.
    By the way, there is no such thing “sourcing .inputrc”, you shouldn’t source it since it’s not a bash-script. I believe this is the reason of most of the command-not-found errors people faced.

  • nbensa says:

    While you’re at it, add to inputrc:

    set completion-ignore-case on

    This way you can to:

    cd deskt[TAB]

    and you’ll get “cd Desktop/”

    To bashrc add:

    shopt -s cdspell

    Now try:

    cd /vr

    For history you can add to bashrc:

    export HISTORYIGNORE=”&:ls:[bf]g:exit:[ \t]*”

    and history will ignore “ls”, bg, fg, exit, commands as well as commands starting with a space or tab. The last one is pretty handy if you want to not record history for commands containing passwords. For example:

    sudo mount -t smbfs -o username=user,password=s3krEtPa55 //server/share /mount/point

    Regards

  • nbensa says:

    I forgot to say you can add a timestamp too:

    In bashrc:

    export HISTTIMEFORMAT=”%F %T ”

    And for those who don’t want to lose default inputrc settings, you can add include to your .inputrc:

    $include /etc/inputrc
    your-custom-settings-here

    Regards

  • Amir Watad says:

    Hey nbensa!
    Thank you for this useful information.
    I didn’t got the thing with not recording commands with passwords, what makes the HISTORYIGNORE to ignore passwords?

    Thank you again :)

  • Trackbacks/Pingbacks

  • [...] (以上程式碼取自:http://www.amirwatad.com/blog/archives/2009/01/30/enhanced-bash/) [...]

  • [...] Enhanced Bash | AmirWatad.com [...]

  • Leave a Reply

    my email
    my photo
    Hi,
    My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
    I'm a Verification Engineer in Mellanox Technologies Ltd.
    I love Linux, the Command Line and the OpenSource Community.
    I used to write Poems (Arabic) when I was able to find time for this.
    January 2009
    S M T W T F S
    « Dec   Feb »
     123
    45678910
    11121314151617
    18192021222324
    25262728293031
    SEO Powered by Platinum SEO from Techblissonline

    Twitter links powered by Tweet This v1.7.4, a WordPress plugin for Twitter.