/bash-up

A mash-up of well-organized files for versatile bash environment configuration

Primary LanguageShell

bash-up: a versatile bash and environment setup utility

bash-up manages a mash-up of well-organized configuration files for your command-line environment and bash configuration.

The objective of bash-up is to provide a unique set of configuration files that you can deploy on as many computer as you like, whatever their system (as long as it is somewhat *NIX and bash compliant).

Principles

Using .profile and .bashrc only as loaders of many many other files…

In the bash-up approach, the .profile and .bashrc files don’t do anything but sourcing other configuration files in your bash-up directory.

Why oh why ? Let’s read next section…

A hierarchy of generic-to-specific files

All configuration files for bash-up are organized by sections (e.g. aliases, functions, completion, etc.) so you can easily organize them.

For each section, files can be common to all systems and all hosts (these are the files placed directly in a section directory), or system-specific (when placed in a system directory, e.g. Linux, Darwin or whatever uname -s may return), or host-specific (when placed in a host directory, using the output of hostname -s to determine the current machine).

Have a look at this example:

bash-up/
|- aliases/
|  |- aliases_one
|  |- some_more
|  |- Linux/
|  |  |- linux_aliases
|  |- Darwin/
|     |- macosx_aliases
|     |- machine_2/
|     |  |- specific_aliases
|     |  |- the_more_the_better
|     |- machine_3/
|        |- for_machine_3
...

Consider me having three computers (lucky me!):

  • machine_1, a good old desktop running Linux
  • machine_2, a MacBook Pro running Mac OS X
  • machine_3, an iMac running Mac OS X

The files aliases_one and some_more will be sourced by all three machines (these are the common files).

linux_aliases will only be sourced by machine_1, as it is the only machine running Linux.

macosx_aliases will be sourced by both machine_2 and machine_3 (as they run Mac OS X). specific_aliases and the_more_the_better will be sourced by machine_2 only, as host-specific files and for_machine_3 is naturally loaded only on machine_3.

Note that the actual name of the file doesn’t matter, so feel free to name them to whatever you think is relevant!

Another good principle is that don’t fear to split your configuration in as many files as you want!

What if…

What if, say, machine_2 dual-boots on both Mac OS X and Linux ?
Okay, create a machine_2 host directory under the Linux system directory and create there symbolic links for all relevant configuration files.

What if I want some more specific system discriminant, like the OS version or the distribution?
Err,… I already thought of that (hey, that’s the proof!) but I’ll work on it for future releases.

The special sections

bash-up counts a set of special sections, namely profile, scripts, templates, private and external.

  • profile is only loaded by the .profile template : all the relevant files in this section will be sourced only at this moment. This is a good place to declare your environment variables.
  • scripts is loaded first by the .bashrc template : all the relevant files in this section will be executed at this moment. Those files can use, generate or modify files in all the other sections.
  • templates section is never loaded : use this directory to put the core of some config files and use it in your scripts.
  • private section is never loaded : use this directory to put some sensitive data that can be added to your config files by some of your scripts. By default, the private section is ignored by the git version control system.
  • external is loaded at the end of the .bashrc template: all files in this section will be symbolically linked to the corresponding location of your home directory (see the following examples):

Generic file:
$BU_DIRECTORY/external/some_generic_config_file will be linked to $HOME/some_generic_config_file on all systems.

Specific file:
$BU_DIRECTORY/external/Linux/computer1/some_specific_config_file will be linked to $HOME/some_specific_config_file only on the computer named computer1, if it is running GNU/Linux.

Installation

Using installation script

There is now an installation script. Simply go the directory where you located the bash-up source and run install.sh from this directory.

Example:

	cd ~/.bash-up
	./install.sh

The install script will handle every step described below. Simply run it again if you change your bash-up source location.

The good-old fashion way

If you don’t want to use the installation script, do the following to start using bash-up,:

  1. Back-up your ~/.profile and ~/.bashrc (or ~/.bash_profile_) files.
    These are important files for your system, and you’ll be happy to find them back if bash-up doesn’t satisfy you.
  2. Back-up your ~/.profile and ~/.bashrc (or ~/.bash_profile_) files.
    (Just to be sure you’ve done it…)
  3. Clone this repository, or download the latest archive of the source to a given bash_up directory
    (I assumed ~/.bash-up as default).
  4. Fill as many section folders you want, with as many configuration files you want, using the hierarchy explained above
    (I give you default and the special sections (except private) to start with).
  5. Replace your ~/.profile and ~/.bashrc (or ~/.bash_profile_) files with the ones provided by bash-up (profile_template and bashrc_template respectively). You can move them, copy them or create symbolic links to replace your original files, it really doesn’t matter.
  6. If you used a non-default directory to download bash-up_, you need to edit the BUDIRECTORY variable in both bash-up‘s .profile and bash-up’s .bashrc files.
    Set this variable to point to the location where your bash-up installation is located.
  7. Done!

Now, next time you’ll log in or start a bash session:

  • bash-up’s .profile will load all the applicable configuration files located in the profile section folder.
  • bash-up’s .bashrc will execute all the scripts applicable to the current computer in the scripts section, load all the applicable configuration files located in all the standard section folders and link all the applicable external configuration files located in the external section.

Note: As a consequence, the profile section folder and all the other special sections are necessary for bash-up to perform correctly.

In further release (yes, this might come someday…)

  • Finer operating system management (OS version, etc..)
  • Manage external config files that could go in subfolders

Credits and references

This project is freely inspired by and complementary to other contributions such as oh-my-zsh or bash-it.

Try them, use them, keep with them if you feel they fulfill your needs better.

License

This program is licensed under the GNU GPL v.3 license. See previous link or the file gpl-3.0.txt for further details.