Organizing “.bashrc”

17 / Aug / 2011 by Himanshu Seth 3 comments

I have been working on Linux for almost 3 years now and have grown to love it a lot.

As with every linux user, the .bashrc file becomes cumbersome and difficult to maintain over a period of time, since there are a lot of project specific aliases, paths, etc

So after working on a couple of projects, I started maintaining separate files for my environment settings. So I just had to create a separate project setting file:

alias myAlias1=’cd /to/project/dir’
alias projectqa=’ssh to@qa’
alias projectDb=’mysql -u<username> -p<password> <project_db_name>’
So, everytime I had to add more project specific settings or separate my settings, I had to create a new settings file and then source it in my .bashrc by adding this line

[bash]. ~/.myProjectSettings[/bash]

As you can guess, after doing this a couple of times, even this was becoming very tedious.

So, I tried to follow the golden rule of convention over configuration.

In my .bashrc, I added the following function :
function sourceAllMySettings(){
for i in `find $FOLDER_TO_BE_SOURCED -type f`;
. $i
##don’t forget to execute the function
and placed all my setting files into the folder :

So, now if I have to add more settings to my .bashrc, I just create a new executable file in this folder and it gets automatically sourced.

Goodbye messy .bashrc, welcome organized (segregated) settings 🙂

~~Himanshu Seth~~


Tag -

Linux Ubuntu

comments (3)

  1. Hitesh Bhatia

    Hi Himanshu , this one really helped me to clean my .bash_profile , Thanks .

    Just one thing ,
    8|don’t forget to execute the function
    you’ve misspelled name of function here .


Leave a Reply

Your email address will not be published. Required fields are marked *