Monday, May 5, 2014

Pimp your Bash console on Windows

Since I have been doing so much Git work I wanted to post some things I do to pimp my Bash console out.

First thing is we need to get to our home directory.  Do this by typing this in your bash console:

cd

This should change your prompt to point to ~.  The next thing is we need to see if there is already a .bashrc file.  The easiest way I have found to do this is to type the following in the bash console:

explorer .

This should open a windows explorer window in your home directory.  Check to see if a .bashrc file exists.  If this file does not exist type the following in the bash console window:

touch .bashrc

Go back to windows explorer and you should now see the .bsahrc file.  Open the file in your favorite text editor.  Here is an example of what I have been putting in my .basrc file:

alias brc="source ~/.bashrc"
alias cls=clear
alias ..='cd ..'
alias cd..='cd ..'
alias dir='ls --color -X'
alias e='explorer .'

h()
{
    cd ~/skydrive/dev;
}

cl() {
    d=$1
    if [[ -z "$d" ]]; then
        d=$HOME
    fi
    if [[ -d "$d" ]]; then
        cd "$d"
        dir
    else
        echo "bash: cl: '$d': Directory not found"
    fi
}



brc an easy way to reload the bashrc file while in the bash console.  This way you don’t have to restart the console each time you make a change.
cls I am used to typing this in DOS
.. a shortcut to go back a directory
cd.. bash wants a space between the cd and the .. this alias lets me forget the space and it doesn’t complain about it.
dir I am used to typing this in DOS
e shortcut to open explorer in the current directory
h shortcut to my start directory where all my code is
cl change directory and list its contents

No comments:

Post a Comment