conf.d like directories for zsh/bash dotfiles
I don’t like messy dotfiles.
The thought of having tons of random configuration entries in files like my .zshrc
really bothers
me, so I implemented something that works like a conf.d
like directory structure for my shell
dotfiles.
I also still use the bash shell in certain situations, and I want a more or less consistent environment, no matter which shell I use (bash, zsh).
With the following setup, it’s possible to have the following:
- A directory called
zshrc.d
, which includes multiple, zsh related configuration files. - A directory called
bashrc.d
, including multiple configuration files concerning bash. - A directory called
rc.d
, including configuration items needed by both shells. - A directory called
login.d
, including elements included by.bash_profile
resp..zlogin
.
This keeps your dotfiles nice and clean, and also allows you do have additional files on systems
where you need them, without them being included on all your systems (e.g. your $GOPATH
).
Here are the dotfiles, that do nothing but include all files in the described directories:
# .bashrc
if [[ $- != *i* ]] ; then
# shell is non-interactive. be done now!
return
fi
# Load all files from .shell/bashrc.d directory
if [ -d $HOME/.shellrc/bashrc.d ]; then
for file in $HOME/.shellrc/bashrc.d/*.bash; do
source $file
done
fi
# Load all files from .shell/rc.d directory
if [ -d $HOME/.shellrc/rc.d ]; then
for file in $HOME/.shellrc/rc.d/*.sh; do
source $file
done
fi
# .bash_profile
if [ -f $HOME/.bashrc ]; then
source $HOME/.bashrc
fi
# Load all files from .shell/login.d directory
if [ -d $HOME/.shellrc/login.d ]; then
for file in $HOME/.shellrc/login.d/*.sh; do
source $file
done
fi
# .zshrc
# Load all files from .shell/zshrc.d directory
if [ -d $HOME/.shellrc/zshrc.d ]; then
for file in $HOME/.shellrc/zshrc.d/*.zsh; do
source $file
done
fi
# Load all files from .shell/rc.d directory
if [ -d $HOME/.shellrc/rc.d ]; then
for file in $HOME/.shellrc/rc.d/*.sh; do
source $file
done
fi
# .zlogin
# Load all files from .shell/login.d directory
if [ -d $HOME/.shellrc/login.d ]; then
for file in $HOME/.shellrc/login.d/*.sh; do
source $file
done
fi
No you can include all sorts of useful functions, settings and aliases by putting individual files
in your .shellrc/*
folders!
You can find my full .shellrc
directory on Github.
Have a look at the README.md for more
information!
Happy housecleaning!