Saturday, April 9, 2011

Arrange bashrc

A simple recursive function can have aid on arranging bashrc files in a clear structure.



Add a line to source it in ~/.bashrc first, and then collect similar rc files into directories respectively.

If a bunch of bash completions were put inside ~/.bash_completion/, like
~/.bash_completion
|-- hg
|-- git
| |-- git
| |-- gitk
| `-- git-common
`-- svk
just one more line
  load $HOME/.bash_completion
would load whole completions.

You may also have many aliases, environment variables, function definitions for different OS like this
~/.bashrc.d
|-- linux
| |-- aliases
| |-- env
| `-- functions
|-- freebsd
| |-- aliases
| |-- env
| `-- functions
`-- darwin
|-- aliases
|-- env
`-- functions

Just one another line
  load "$HOME/.bashrc.d/$(lower $(uname))"
can load correct system-specified rc files.