02 September 2010

Setting up your bash prompt for colours, aliases and other things

One of the little joys in life is to have a nice coloured bash prompt and a lot of aliases to simplify navigation in bash.

I've placed most of my commands in ~/.bash_aliases.


To know how to colour a terminal, see this and this
Being able to create aliases to commands is one of the best things I've found out about the bash shell. You'll find a similar functionality in MS-DOS, called doskey.

These are the aliases I use in bashrc. Typing "cd .." became so annoying that the alias "f" (for "fall" to the below directory) became a handy tool.


# User specific aliases and functions
alias bashrc='vim ~/.bashrc;source ~/.bashrc;echo bashrc has been sourced'

alias bashaliases='vim ~/.bash_aliases;source ~/.bash_aliases;echo bash_aliases has been sourced'    
alias bashprofile='vim ~/.bash_profile;source ~/.bash_profile;echo bash_profile has been sourced'
alias aliases="clear;cat ~/.bash_aliases|grep --color \"alias\""
alias home='cd;ls;pwd'
alias root='cd /;ls;pwd'
alias die='halt -p'
alias desktop='cd ~/Desktop;ls;pwd'
alias f='cd ..;ls;pwd'
alias ff='cd ../..;ls;pwd'
alias fff='cd ../../..;ls;pwd'
alias ffff='cd ../../../..;ls;pwd'
alias fffff='cd ../../../../..;ls;pwd'
alias ffffff='cd ../../../../../..;ls;pwd'
alias fffffff='cd ../../../../../../..;ls;pwd'
alias ffffffff='cd ../../../../../../../..;ls;pwd'
alias home='cd;ls;pwd'
alias root='cd /;ls;pwd'
alias shtdn='halt -p'

alias startsql="service mysqld start"
#adding a hibernate option which I found while using Fedora20
alias hibernate='systemctl hibernate'
#--- For a coloured, customised prompt
# 0 is for non-bold colour. Replace it with 1 for bold
# 31m is the colour
# \u makes it show the username
# \h makes it show the address
# \W makes it show the directory name. Use \w for showing the full path
#export PS1="\e[0;32m[\u@\h \W]\$ \e[m"

export PS1="\e[1;32m[\W] \e[m"

alias br='xrandr --output eDP1 --brightness 0.5'
alias brightness='xrandr --output eDP1 --brightness '
 

alias night='redshift -O 2300 -g .8'
alias day='redshift -O 2500 -g .8'
alias normal='redshift -x'
alias swap='sudo swapoff -a; sudo swapon -a'
#to shift memory from swap space to RAM

#To play a beep in Ubuntu after running some program from the bash prompt.
alias beep='paplay
/usr/share/sounds/freedesktop/stereo/complete.oga'