Devoured By Lions

the eternal struggle to tame complexity

Configuring Bash on OS X

I’m moving to OS X for my work machine and one of the first things I like to set up is my terminal. OS X has thankfully moved to bash. I initially tried adding aliases to my ~/.bashrc but they were not getting picked up. This is because the Terminal application spawns shells as login shells.

For login shells Bash will read the following files:

1. ~/.bash_profile
2. ~/.bash_login
3. ~/.bash_profile

For non-login interactive shells Bash will read the following file:

1. ~/.bashrc

See http://en.wikipedia.org/wiki/Bash#Startup_scripts

I have always used ~/.bashrc and just assumed this file was sourced under all circumstances. However I now suspect that this perception was due to the fact that typical Linux setups will provide a login script (e.g. ~/.bash_profile, or the system default) which itself sources ~/.bashrc. So I suppose this behavior is more of a convention. Which OS X does not follow.

The solution is simple enough (philosophical issues on how to properly structure these files aside): simply link the login script to the ~/.bashrc script.

ln -s ~/.bashrc ~/.bash_profile


The next step is to get rid of the annoying alert “bell” that is enabled by default in bash (and by the terminal application? the *nix terminal/character-device layer is complicated enough that I can’t pretend to understand how it actually works under the hood). Bash uses a library called readline to get read line input (surprise!). Readline uses the ~/.inputrc for various settings. You can set “set bell-style visible” (or “set bell-style off” if you don’t want it at all) to quell the annoying beep emitted whenever you hit tab for a completion (which for me is every half second). This did not quite do the job for me - the terminal was still beeping. So I had to go into the Terminal application settings and change the bell style to visible under the shell tab.

Hope that helps.