base
                                
                                 base copied to clipboard
                                
                                    base copied to clipboard
                            
                            
                            
                        A simple framework for sharing Bash profiles, reusable shell libraries, and commands across hosts and teams. Contains builtin libraries for common functions like logging, error handling, and assertion...
What is Base?
                Great things are done by a series of small things brought together.
                                                                 - Vincent van Gogh
Base is a sharing platform for shell settings, libraries, and light-weight tools. It gives a structured way for Bash users to organize the following across multiple hosts:
- .bash_profile
- .bashrc
- generic Bash libraries and commands
- company specific Bash libraries, commands, and configuration
- team specific Bash libraries, commands, and configuration
- user specific settings (aliases, functions, Bash settings)
- Bash libraries, commands, and configuration that are shared across teams
It can benefit anyone who engages with Mac/Linux command line to get their work done.
Requirements
Base needs Bash version 4.2 or above.
How can I get set up?
Set up is easy. Essentially, this is what you have to do:
- Check out Base. The standard location for Base is $HOME/base.  In case your git directory is elsewhere, symlink $HOME/gitto it or specify the path by settingBASE_HOMEin$HOME/.basercfile.
- Consolidate your individual settings from your current .bash_profileand.bashrcinto$USER.shfile. Place this file underbase/userdirectory and check it in to git.
- Make a backup of your .bash_profile. Replace this file with a symlink tobase/lib/bash_profile.
- Make a backup of your .bashrc. Replace this file with a symlink tobase/lib/bashrc.
Log out and log back in or just do exec bash and you are all set!
Here is an example:
cd $HOME
mkdir git && cd git
git clone [email protected]:codeforester/base.git
cd $HOME
mv .bash_profile .bash_profile.safe && ln -sf $HOME/base/lib/bash_profile .bash_profile
mv .bashrc       .bashrc.safe       && ln -sf $HOME/base/lib/bashrc       .bashrc
cp $USER.sh $HOME/base/user
cd $HOME/base
git add user/$USER.sh
git commit -m "Adding the initial version of $USER.sh"
git push
If you don't want to disturb your .bash_profile and .bashrc, you can still use Base in a less full-fledged manner.  See the FAQ section for details.
How does Base work?
In a typical setting, .bashrc sources in $BASE_HOME/base_init.sh which does the following:
- source in lib/stdlib.sh
- source in company/lib/company.shif it exists
- source in company/lib/bashrcif it exists, if the shell is interactive
- source in user/$USER.shif it exists and if the shell is interactive
- source in team specific bashrc from team/<team>/lib/bashrcfor each team defined inBASE_TEAMandBASE_SHARED_TEAMSvariables, if the shell is interactive. Note thatBASE_TEAMandBASE_SHARED_TEAMSshould be ideally set inuser/$USER.sh.
- source in team specific library from team/<team>/lib/<team>.shfor each team defined inBASE_TEAMandBASE_SHARED_TEAMSvariables, if they exist
- update $PATHto include the relevantbindirectories- $BASE_HOME/binis always added
- $BASE_HOME/team/$BASE_TEAM/binis added if- $BASE_TEAMis set in- user/$USER.sh
- $BASE_HOME/team/$BASE_TEAM/binis added for each team defined in- $BASE_SHARED_TEAMS(space-separated string), set in- user/$USER.sh
- $BASE_HOME/company/binis always added
 
Directory structure

Environment variables
- BASE_HOME
- BASE_DEBUG
- BASE_TEAM
- BASE_SHARED_TEAMS
- BASE_OS
- BASE_HOST
- BASE_SOURCES
Functions exported by base_init.sh
- import       - sources in libraries from any place under BASE_HOMEdirectory
- base_update  - does a git pullon Base git directory; add it touser/<user>.shto "auto update" Base
FAQ
My git location is not $HOME/base.  What should I do?
You can either
- 
specify your Base location in $HOME/.baserc, likeBASE_HOME=/path/to/base 
- 
symlink $HOME/baseto the right place
You need to do this on every host where you want Base.
I want to keep my personal settings private, and not in git. What should I do?
- 
write a one-liner in user/$USER.shlike this:source /path/to/your.settings 
You would need to manage this file outside of Base.
I do want to use the default settings. What should I do?
Add this to your user/$USER.sh file:
import lib/base_defaults.sh
I want to make sure I keep my Base repository updated always. How can I do it?
Add this to your user/$USER.sh file:
base_update
I don't want to reorganize my .bash_profile or .bashrc.  Can I still use Base?
Yes, you can, though you will lose the flexibility of keeping your .bash_profile and .bashrc synced across hosts in case you are working with multiple hosts.
To turn on Base upon login, add this to your .bash_profile:
export BASE_HOME=/path/to/base
source "$BASE_HOME/base_init.sh"
after making sure you have the base repo checked out under $BASE_HOME directory.
If you don't want to change your .bash_profile at all, you can still turn Base on and off as needed. First, make sure BASE_HOME is set appropriately, ideally in your .bash_profile.
Run this command to get a shell with Base turned on:
$BASE_HOME/base.sh shell
or $BASE_HOME/base.sh
Debugging
- You can turn on debug mode by touching $HOME/.base_debugfile. You can also do the same by setting environment variableBASE_DEBUGto 1.
- You can add set -xto$HOME/.basercfile to trace the execution in detail.