One of my biggest frustrations any time I move to a new server: migrating to a new data center, changing jobs or simply adding new servers somewhere in between is keeping my customized shell environment while giving each server a bit of customizability. Of course, in a linux environment, we have our coveted .bashrc that will do this. But what has helped me through this process time and time again is building my .bashrc to allow for server-specific extensions. Here’s how I’ve done it.
I really have three different classes of servers I work with: my personal boxes (desktops, etc), development boxes and production boxes. In each of these environments, I want a little something different. But in all, I want most of the things the same.
Your Standard .bashrc
Amongst other things, I have a few standard settings in my default .bashrc. Like what’s listed below: a few helpful alias’, my terminal format settings and (not listed) a number of smaller functions and screen magic that I like to bring to every linux-based server/computer I have an account on.
alias …="cd ../.."
alias ….="cd ../../../"
alias sls=’screen -ls’
alias x=‘exit’
alias lt="ls -ltr"
alias l=‘ls -ltr’
alias ll=‘ls -ltr’
export PERL5LIB=$HOME/lib
export PS1=‘\#:\u@\h:\w$ ‘
Extend It
Here’s the magic that will let you extend this to specific servers:
if [ ! $TERM = "dumb" ];
then
HRC=".${HOST}rc"
if [ -r $HOME/$HRC ];
then
echo "Loading $HOME/$HRC"
source $HOME/$HRC
fi
stty erase ^?
fi
Simple enough, but it allows for the extension of the default .bashrc by looking for a .`hostname`rc which can be placed anywhere in your .bashrc. If at the end, it will grant you a generalized server-specific extension similar to other prototypical languages. It’s certainly helped me. I now can keep a single, global .bashrc and a small handful of customizations across the three platforms I mentioned earlier. Now, when managing in upwards of 30 servers between work and home, I have only 4 .bash files to manage rather than 30. It’s not a perfect solution, but one that works for me and hopefully one that can help you out too.
Have your own similar application of .bashrc extensions you prefer over this? Comment about it. I’m always looking for better ways to optimize my server-side experience.