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
No related posts.
17 Comments to Enhanced Bash
Trackbacks/Pingbacks
[...] Enhanced Bash [...]
[...] (以上程式碼取自:http://www.amirwatad.com/blog/archives/2009/01/30/enhanced-bash/) [...]
[...] Enhanced Bash | AmirWatad.com [...]
Leave a Reply
About Me
Tags
Categories
- Algorithms
- Bash
- BlackBerry
- Collaboration
- Command Line
- Cool Tricks
- Easter Eggs
- Ebooks
- Firefox
- Hardware
- Humor
- iPhone
- Linux
- Linux Development
- Linux Kernel
- Networks
- Open Knowledge
- Other
- Productivity
- Programming
- Regular Expressions
- Science
- Security
- Shell Scripts
- Short Posts
- Social Networks
- Thoughts
- Tools
- Vim
- Web Development
- Websites
Popular Posts
Calendar
Archives
- September 2010 (2)
- August 2010 (2)
- July 2010 (5)
- June 2010 (1)
- May 2010 (1)
- April 2010 (3)
- March 2010 (1)
- January 2010 (1)
- December 2009 (2)
- September 2009 (13)
- July 2009 (1)
- June 2009 (6)
- May 2009 (4)
- March 2009 (18)
- February 2009 (10)
- January 2009 (10)
- December 2008 (7)
- November 2008 (8)
- October 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)

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
Using Kubuntu 8.10. There is no .inputrc file in my home directory.
Hi, I get this errormessage byy the .inputrc:
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)
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.
Hi,
For anybody who couldn’t get this work, can you email me your .inputrc file?
Amir DOT Watad AT gmail DOT com
E-mail sent.
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
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
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
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.
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
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
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