{ ^_^ } sinustrom Solving life, one problem at a time!

Some useful .bashrc tips

Author: Zoltan Puskas
Categories: linux

Using the shell in Linux makes a lot of operations more convenient and faster. In order to make things even more comfortable here are a few tips to setup the bash shell. Put these lines in your ~/.bashrc file.

Ignore history duplicates

This will ignore duplicate history elements in the ~/.bash_history file.

export HISTIGNORE="&"

History size

This will set the size of the ~/.bash_history file. The number indicates the number of lines (by default usually 500). This option combined with the option above will provide quite a big history of unique commands (which means less typing in future ;).

export HISTSIZE=1000

Delete word

On pressing Ctrl-W it will delete a word backward (just like in Vim)

bind "^W":backward-delete-word

History search with arrows

Most will be familiar with the Ctrl-R command history search feature. This is something similar but more practical. One has to type in the few first characters and then use the ↑/↓ (up/down) arrow keys to step through the command history that match that beginning.

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

Faster cd upwards

These aliases will bind the upwards cd (change directory) commands to an arbitrary number of dots. This will speed up the most common cases. One could have more levels of course but after some degree it becomes impractical.

alias ..="cd .."
alias ...="cd ../../"
alias ....="cd ../../../"
alias .....="cd ../../../../"

Make mc exit to current directory

This will make mc exit to the directory of the active panel instead of the directory mc was started from.

source /usr/libexec/mc/mc.sh

Bash argument auto completion

In order for the shell to auto complete command line arguments in Gentoo you have to put this into your ~/.bashrc file. Don’t forget to add some commands you want for bash auto completion using the eselect command.

source /etc/profile.d/bash-completion.sh