Last active
October 6, 2021 15:38
-
-
Save bcomnes/5053fca2d7be573c0abd to your computer and use it in GitHub Desktop.
bashrc utopia
This file contains hidden or 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 hidden or 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" |
Author
Author
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.dstyle number prefixes: