Monday, June 18, 2012

Pimp your bashrc

Although I've been a Linux user for many years, I have only recently started experimenting with, and tweaking my ~/.bashrc file. I guess better late than never...right?

It's still very much a work in progress, but here is what I've come up with so far.

First, my PS1:
PS1='\[\033[1;32m\][\u@\h \[\033[31m\]\W\[\033[34m\]$(__git_ps1 " (%s)")\[\033[1;32m\]]\\$\[\033[m\] '

This was the first tweak I made, and I blogged about it here (and updated the post a few times in the process).

After doing that I started adding aliases, and I've collected a pretty good list so far:

First, I've fixed my most common typo...correcting isntall to install:

##Fix Typos 
alias isntall='install'

Then, I set up a few for SSH connections:

##SSH Connections 
alias server='ssh server -l jaysonr' 
alias railsvm='ssh railsdev-vm -l jaysonr' 
alias djangovm='ssh djangodev-vm -l jaysonr'

Next, I added some for package management:

##Package Management 
alias update='sudo yum update' 
alias install='sudo yum install' 
alias remove='sudo yum remove' 
alias pkgsearch='yum search'

A few frequently used directories:

##Frequently Used Directories 
alias home='cd ~' 
alias desktop='cd ~/Desktop' 
alias downloads='cd ~/Downloads' 
alias dropbox='cd ~/Dropbox'

A few miscellaneous shortcuts:

##Misc Shortcuts 
alias df='df -h' 
alias ls='ls -F' 
alias lsa='ls -alF --color=auto' 
alias lsl='ls -lF --color=auto' 
alias rm='rm -i' 
alias mv='mv -i' 
alias cp='cp -i' 
alias un='tar -zxvf' 
alias top='htop'

And finally the ability to control a few VM's I run headless & SSH into:

##VirtualBox CLI Machines 
alias startrailsvm='VBoxManage startvm rails_dev --type headless' 
alias stoprailsvm='VBoxManage controlvm rails_dev savestate' 
alias startdjangovm='VBoxManage startvm django_dev --type headless' 
alias stopdjangovm='VBoxManage controlvm django_dev savestate'

So, what are some cool things you have in your ~/.bashrc? I'm always looking to learn new tricks.

2 comments:

  1. .bash_profile is executed (sourced) once per login, and .bashrc once per shell startup. Environment variables (such as PS1) have traditionally been placed in the .bash_profile since environment variables are inherited by child processes; aliases can't go there because they're not inherited. It won't make any significant performance difference on a modern system unless you have a large set of envars, but it will mildly confuse old-school admins to see PS1 in .bashrc :-)

    ReplyDelete
  2. I like:
    export LESS='FiX'

    It prevents the man pages from disappearing when you exit them.

    ReplyDelete