bashrc utopia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ~/.bash_profile | |
# | |
# Do everything in bashrc | |
[[ -f ~/.bashrc ]] && . ~/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# ~/.bashrc | |
# | |
# .d folder style bashrc | |
# https://gist.github.com/bcomnes/5053fca2d7be573c0abd | |
# If not running interactively, don't do anything | |
[[ $- != *i* ]] && return | |
run_scripts () { | |
local script | |
for script in $1/*; do | |
# skip non-executable snippets and folders | |
[ -f "$script" ] && [ -x "$script" ] || continue | |
# execute $script in the context of the current shell | |
. $script | |
done | |
} | |
# if DEFAULT_PATH not set | |
if [[ -z "$DEFAULT_PATH" ]] ; then | |
# set it! | |
export DEFAULT_PATH=$PATH | |
fi | |
# reset path to default path for idempotent bashrc sourcing | |
export PATH=$DEFAULT_PATH | |
# bashrc folder | |
BASHRCD=~/.bashrc.d | |
# run all the bash settings | |
run_scripts "$BASHRCD" |
You can also call this same pattern for subfolders e.g. .bashrc.d/darwin
, .bashrc.d/linux
etc.
#!/bin/bash
# `.bashrc.d/platformrc.sh`
# https://gist.github.com/bcomnes/13711d12237e866de5ca
if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
run_scripts ./darwin
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Do something under GNU/Linux platform
run_scripts ./linux
echo "loading linux"
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
# Do something under Windows NT platform
run_scripts ./mingw32_nt
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Load order can be further enforced with
init.d
style number prefixes: