• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
  • Created over 12 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Launch different bash configurations for Linux vs OSX, interactive vs batch

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):

  • ~/.bashrc
  • ~/.bash_profile
  • ~/.profile (only if your scripts are all 'sh' compatible- otherwise get rid of it altogether)
  • ~/.bash_login

And then you can use these instead:

  • ~/.bashrc_once: sourced at least once, and in most circumstances only once- before anything else.
  • ~/.bashrc_all: sourced on every bash instantiation
  • ~/.bashrc_script: sourced only when non-interactive / batch
  • ~/.bashrc_interactive: the one you'll probably fill up (mutually exclusive with ~/.bashrc_script)
  • ~/.bashrc_login: sourced only when an interactive shell is also a login.

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:

  • $SHELL_PLATFORM (either LINUX, OSX, BSD, CYGWIN or OTHER),
  • shell_is_linux,
  • shell_is_osx,
  • shell_is_cygwin,
  • shell_is_interactive,
  • shell_is_script.

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

  • Obviously don't simply blow away your existing startup scripts if they have anything in them- you'll need their content to populate the new bashrc_* stuff.

  • If you symlink ~/.profile to this script you may be fine, but since it sometimes gets sourced by a true sh command and the script currently has some bash-only stuff, it might not. Specifically, remove the symlink to ~/.profile if anything starts acting strange on startup or xwindows-based login.

  • Be very careful what you put in .bashrc_all and .bashrc_script - it may slow the system down. I put them there for conceptual completeness- that doesn't mean you have to use them (:

Additional Configuration

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

  • EXPORT_FUNCTIONS: set it to false to disable the export of $SHELL_PLATFORM and all the shell_is_* functions and avoid polluting all the other shells' environments.

  • Inside bashrc_dispatch you can change PRF= to a location other than ${HOME}/. to have it look for your new bashrc_* scripts somewhere else.

  • In general, modify your bashrc_dispatch script as much as you need to. You'll see there's not a lot of code there. Much less code then there are comments in this readme. Please share a patch if you like your modification.

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.

More Repositories

1

epgsql_pool

Fork of Will Glozer's erlang postgresql pool server, so it can be maintained and polished.
Erlang
31
star
2

tcpshunt

Hand off a TCP connection to another server
C
11
star
3

monocore

IN PROGRESS. a minimalist monospace font ideal for programming and console systems.
Ruby
10
star
4

autocolors

Automatically generate editor-agnostic colorschemes that look freaking awesome.
Vim Script
7
star
5

git-loc

Quick lines-of-code calculator grouped by day for git repositories
5
star
6

neworld

Game stuff in haxe
Haxe
4
star
7

zml

Concise markup language + templating system inspired by haml, SLiP, sexp2xml, and tenjin.
Python
4
star
8

libhhash

Automatically exported from code.google.com/p/libhhash
C
3
star
9

murphytango.vim

High contrast colorscheme (full featured) based on murphy, tango, and desert256
Vim Script
3
star
10

exrss

Elixir robust RSS polling (etc.)
Elixir
3
star
11

udon

Universal Document & Object Notation
JavaScript
3
star
12

ngx-rome

Let nginx serve up a request from multiple sources without using SSI. (Divide and Conquer)
JavaScript
3
star
13

achtung

New language on top of the Erlang virtual machine sharing all of Erlang's common idioms. Also parsing expression grammar (PEG) work.
Erlang
3
star
14

autohighlight

Automatically generate VIM and emacs coloring from BNF grammars (Automatically exported from code.google.com/p/autohighlight)
Python
3
star
15

zombiehour

Web game
Erlang
3
star
16

pywebtest

Plain-english, fast, headless (mostly), lightweight, and standards-compliant acceptance and web testing.
Python
3
star
17

epgsql

Fork of Will Glozer's erlang postgresql api. Here for maitenance and evolution.
Erlang
2
star
18

gx

Generic eXtra C macros. Miscellaneous, probably of little interest to anyone beside myself.
C
2
star
19

genmachine

Generates parsers based on a fancy state-table. Takes a state table where the following are defined: state, input+conditions, accumulate-action, pre-transition-actions, and transition-to. It takes that state table and generates very fast parsers. Similar to Ragel. Currently only outputs pure Ruby.
Ruby
2
star
20

haxe.vim

New and improved haxe syntax file for vim
Vim Script
1
star
21

neutron.vim

Light background gvim colorscheme, the yin to zenburn's yang. Fully featured (coherent colors for almost all syntax groups)
Vim Script
1
star
22

decoupler

Like a buffered named pipe with an actual file and possibly multiple readers.
C
1
star
23

APG

Analytical Parsing Grammars
TeX
1
star
24

jaw.io

Joseph Wecker website
JavaScript
1
star
25

erlbuild

A simplified Erlang build / make / makefile utility. Can also combine beams into self-contained escript executable.
Erlang
1
star
26

mx

Meta-control/config/context manager. A kind of superset of git/rvm/pythonbrew/rails-environment type tools...
Shell
1
star
27

erldashboard

Right now, just a tool for pulling in emails and using them to potentially trigger actions
Python
1
star
28

metacon

Tool with some similarities to puppet but specializing in fast development iteration and continuous deployment. For use with justin.tv / twitch.tv project clusters.
Shell
1
star
29

udon-ruby

Ruby gem for parsing and generating Udon documents/objects
Ruby
1
star
30

zerl

Erlang web server & framework. View-centric. Optimized for speed of development and speed of content delivery.
Erlang
1
star
31

construct

Intelligent procedural makefile replacement based on fabricate.py
Python
1
star
32

uthash

Official now at: https://github.com/troydhanson/uthash -- [was Clone of http://tkhanson.net/cgit.cgi/uthash.git until troydhanson decides to do an official one here (: ( http://uthash.sourceforge.net/ )]
C
1
star
33

tpl

Efficient C serialization. Clone of http://tkhanson.net/cgit.cgi/tpl.git until troy does his own official clone on here (: ( http://tpl.sourceforge.net/ )
C
1
star
34

ascendant

Baseline-aligned design framework
CSS
1
star
35

vim-code-tag-renderer

Given a text file, it replaces <code> blocks with html exactly like what appears in (your) gvim. For when pygments isn't cutting it for your blog or documentation.
1
star
36

libveb

Automatically exported from code.google.com/p/libveb
C
1
star