My .bash_profile & .bashrc rundown

First and foremost my .bash_profile is 90% alias’ 10% including other stuff
So without further ado, opening my .bash_profile I’ll see this right away.

if [ -f ~/.bashrc ]; then
 . ~/.bashrc

Woah, hold it.. What’s the difference between .bashrc and .bash_profile?
According to the bash man page .bash_profile is executed for login shells (Imagine tunneling through ssh to a remove server.), while .bashrc is executed for interactive non-login shells.

The exception to the rule being Mac OS which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. 

Most of the time I don’t want to maintain two separate config files for login and non-login shells (namely .bashrc and .bash_profile)
When I set a PATH, I want it to apply to both.
Therefore i’m sourcing PATH and common settings in .bashrc from .bash_profile.

Because of this, I’ll be including (and explaining) the contents of both files in this post.

Moving on…

if [ -f /etc/bashrc ]; then
 . /etc/bashrc

This one shouldn’t require much explanation, if you’re reading this part, I’ll assume you already understand the concept of sourcing.
Almost every apache/nginx/litespeed/whatever-linux-based-host has that kind of mumbo-jumbo at the top of their users .bash_profile or .bashrc files.
But to the non-initiated of you that doesn’t know, this fetches the system-wide bash definitions.

Moving on we’ll find all sorts of mumbo-jumbo magic.

# -l use a long listing format
# -h Human readable sizes
# -a Do not ignore entries starting with . (aka. show hidden files)
# --color Colorizes the output
alias ls="ls -lha --color --time-style='+%Y-%m-%d %H:%M:%S'"
alias myip="curl"
alias phpunit="php ~/bin/phpunit.phar"
alias wp="php ~/bin/wp-cli.phar"
alias diff="colordiff -bur"
alias ccat="pygmentize"

I have installed colordiff and pygmentize for the diff and ccat alias’ to work.

At work I have the pleasure (others would think unfortunate.) of using a Mac, On which --time-style Doesn’t work.
(Additionally i need ls -G for colored output, which in other systems means grouping, not colors. . .  )

If you’re feeling comfortable installing gnu coreutils, you can do brew install coreutils and get --time-style to work that way.
Obviously homebrew (Mac OS 3rdparty package manager) is required.

This one have definetily saved me some typing on the keyboard. A good developer is lazy. never writes the same thing twice.

alias brewit='brew update && brew upgrade'

And this too.

alias reload='. ~/.bash_profile'

Sometimes every now and then, I have some script that needs testing on a different PHP version than the server’s running.
For that case I have a seperate user set up (Don’t want to eff everything else up in the process), with this frisky oneliner in the .bash_profile.

alias php="/usr/bin/php71"

Or this …

alias ruby="/bin/ruby"

This one i got from a fellow developer.

alias wtf="man"

Back to that .bashrc file of mine, manipulating PATH variables is always fun stuff.
If you have already read my previous post about installing vim on a shared host. You may already know why, and some edge cases where manipulating PATH can be a good idea.


Once again i’ll assume you are somewhat tech-sawy reading through all this, but in case you don’t know:

PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located.