Build and Release

A continuous learner for experience and life.

Thoughs About Alias Settings in .bashrc

Sometimes, when we install a package, just as, tomcat, we need to append some lines in .bashrc to add and export the tomcat/bin in the system PATH, then source the entire .bashrc to enable it. It is some a little risky (when you forget append $PATH, :) ) and painful, especially when we try to automate the installation process.

When we have several machines, we always need to synchronize the .bashrc file among them. I hate to copy them when I have more than 3 boxes.

Then I have the below thoughs to simplify it, with a github repository. Of course, you don’t need do these things manually again, Just try to clone the github repo at the bottom of this article.

1. We can create a folder, name it as:

1
~/.bashrc.d/

inspired by rc.d, init.d, conf.d etc;

2. We create some files under the folder, name them as:

1
2
3
~/.bashrc.d/linux/git.alias.bash
~/.bashrc.d/linux/java.path.bash
~/.bashrc.d/linux/editor.bash

3. We add an entry point into ~/.bashrc:

1
2
3
4
5
6
OS=$( uname | tr '[:upper:]' '[:lower:]')
if [ -d $HOME/.bashrc.d ]; then
  for SCRIPT in $( ls $HOME/.bashrc.d/${OS}/* ); do
    . ${SCRIPT}
  done
fi

4. Then we run the source command to enable them:

1
source ~/.bashrc

5. Done!

Here is the repository:

https://github.com/lifuzu/bashrc.d.git

Run the command to clone it, fork it, and enjoy!

Written with StackEdit.

Comments