Skip to content

Instantly share code, notes, and snippets.

@awaxa
Last active August 29, 2015 14:06
Show Gist options
  • Save awaxa/ce3dbf17d9f37679dfef to your computer and use it in GitHub Desktop.
Save awaxa/ce3dbf17d9f37679dfef to your computer and use it in GitHub Desktop.
# Copyright (c) 2014 Greg Kitson https://github.com/awaxa
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#
# loads rc.d files for the current shell
#
# example behavior given the following assumptions,
# the command reported by ps for the current process is 'bash'
# the kernel reported by uname is 'Linux'
# this script will load files in $dir that match this pattern in alphabetical
# order:
# *.all
# *.all.linux
# *.all.bash
# *.all.bash.linux
# any of the above with .interactive appended will be loaded for interactive
# sessions only
#
# to protect itself from nullglob errors, the script will touch a set of empty
# files named 00-nullglob-safety.*
dir=$HOME/.rc.d
shell=$( ps -o command $$ | grep -o '[a-z]*sh' )
kernel=$(uname -s | tr '[:upper:]' '[:lower:]')
if [ ! -f $dir/00-nullglob-safety.sh.$shell ] ; then
for shell in all $shell ; do
touch $dir/00-nullglob-safety.${shell}.${kernel}.interactive
touch $dir/00-nullglob-safety.${shell}.$kernel
touch $dir/00-nullglob-safety.${shell}.interactive
touch $dir/00-nullglob-safety.$shell
done
fi
profiles="$( echo $dir/*.all )"
profiles="$profiles $( echo $dir/*.all.$kernel )"
profiles="$profiles $( echo $dir/*.$shell )"
profiles="$profiles $( echo $dir/*.${shell}.$kernel )"
case $- in
*i*)
profiles="$profiles $( echo $dir/*.all.interactive )"
profiles="$profiles $( echo $dir/*.all.${kernel}.interactive )"
profiles="$profiles $( echo $dir/*.${shell}.interactive )"
profiles="$profiles $( echo $dir/*.${shell}.${kernel}.interactive )"
;;
esac
for file in $( echo $profiles | xargs -n1 basename | sort ) ; do
. $dir/$file
done
# vi: ft=sh
@awaxa
Copy link
Author

awaxa commented Nov 20, 2014

Future revisions will be tracked in my dotfiles repository, here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment