josephwecker / bashrc_dispatch

Launch different bash configurations for Linux vs OSX, interactive vs batch
137 stars 9 forks source link

bashrc_dispatch

Different bash configurations for Linux vs OSX, interactive vs batch

(For related discussion see hackernews)

Are you tired of trying to remember what .bashrc does vs .bash_profile vs .profile?

Are you tired of trying to remember how Darwin (Mac OS X) treats them differently from Linux?

Are you tired of not having your ~/.bash* stuff work the way you expect?

Setup / Usage

Symlink all of the following files to bashrc_dispatch (after reading warnings below):

And then you can use these instead:

To reiterate,

  1. ~/.bashrc_once will be run before any of the others, but then won't be run again (ideally).
  2. ~/.bashrc_all will run next, and will be run on every bash invocation. (so keep it light)
  3. Then either ~/.bashrc_script or ~/.bashrc_interactive will be run next depending on whether or not the bash invocation is interactive.
  4. Finally, sometimes, like when you first ssh into a machine or often when opening a new terminal window on a mac, the ~/.bashrc_login will be run after the ~/.bash_interactive. So ~/.bashrc_login is the one where you'd echo a banner or whatever. For things like setting the PATH, use .bashrc_once instead.

Exported Stuff

In addition to the dispatching, you'll forever have the following available:

The functions are meant for clean conditionals in your new ~/.bashrc_* scripts like:

$  shell_is_linux && echo 'leenux!'

or something like:

$  if shell_is_interactive ; then echo 'interact' ; fi

Warnings

Additional Configuration

There are few knobs you can turn to make bashrc_dispatch behave as you prefer.

Authors

Development

Code : https://github.com/josephwecker/bashrc_dispatch

Report issues : https://github.com/josephwecker/bashrc_dispatch/issues

License

This is free software released into the public domain.