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.
Base needs Bash version 4.2 or above.
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/git
to it or specify the path by settingBASE_HOME
in$HOME/.baserc
file. - Consolidate your individual settings from your current
.bash_profile
and.bashrc
into$USER.sh
file. Place this file underbase/user
directory 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.
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.sh
if it exists - source in
company/lib/bashrc
if it exists, if the shell is interactive - source in
user/$USER.sh
if it exists and if the shell is interactive - source in team specific bashrc from
team/<team>/lib/bashrc
for each team defined inBASE_TEAM
andBASE_SHARED_TEAMS
variables, if the shell is interactive. Note thatBASE_TEAM
andBASE_SHARED_TEAMS
should be ideally set inuser/$USER.sh
. - source in team specific library from
team/<team>/lib/<team>.sh
for each team defined inBASE_TEAM
andBASE_SHARED_TEAMS
variables, if they exist - update
$PATH
to include the relevantbin
directories$BASE_HOME/bin
is always added$BASE_HOME/team/$BASE_TEAM/bin
is added if$BASE_TEAM
is set inuser/$USER.sh
$BASE_HOME/team/$BASE_TEAM/bin
is added for each team defined in$BASE_SHARED_TEAMS
(space-separated string), set inuser/$USER.sh
$BASE_HOME/company/bin
is always added
- BASE_HOME
- BASE_DEBUG
- BASE_TEAM
- BASE_SHARED_TEAMS
- BASE_OS
- BASE_HOST
- BASE_SOURCES
- import - sources in libraries from any place under
BASE_HOME
directory - base_update - does a
git pull
on Base git directory; add it touser/<user>.sh
to "auto update" Base
You can either
-
specify your Base location in
$HOME/.baserc
, likeBASE_HOME=/path/to/base
-
symlink
$HOME/base
to the right place
You need to do this on every host where you want Base.
-
write a one-liner in
user/$USER.sh
like this:source /path/to/your.settings
You would need to manage this file outside of Base.
Add this to your user/$USER.sh
file:
import lib/base_defaults.sh
Add this to your user/$USER.sh
file:
base_update
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
- You can turn on debug mode by touching
$HOME/.base_debug
file. You can also do the same by setting environment variableBASE_DEBUG
to 1. - You can add
set -x
to$HOME/.baserc
file to trace the execution in detail.