Image for post
Image for post

Use .bashrc.d directory instead of bloated .bashrc

Quentin ADAM
Aug 28, 2017 · 1 min read

Bashrc file or .profile are the place where we put the initialization of the bash/zsh/fish shell, and lot’s of software want to add a line here, mainly to init some environment variable, or change path (BTW there is a feature to do that on OSX). The result is a bloated, unreadable file for init. So, let’s split it in several files.

You will be able to list your init parts like this:

denis:~ waxzce$ ls .bashrc.d/
alias-vlc.bashrc
autoenv.bashrc
autojump.bashrc
commented-waht-isit.bashrc
dcos.bashrc
git-alias.bashrc
go_path.bashrc
hist.bashrc
history.bashrc
homebrew_management.bashrc
iterm2.bashrc
nvm.bashrc
path_local.bashrc
rbenv.bashrc
rust.bashrc
sdkman.bashrc

How to switch?

First, create a directory

mkdir ~/.bashrc.d
chmod 700 ~/.bashrc.d

Then add this to your actual .bashrc or .bash_profile (on top)

for file in ~/.bashrc.d/*.bashrc;
do
source “$file”
done

Then just split the file inside the ~/.bashrc.d directory with precise MYFILE.bashrc file. You’ll need to give them execution rights too

chmod +x ~/.bashrc.d/*.bashrc

Thank you to Yoann Grange for the picture

UPDATED with the suggestions of Jérôme Le Gal, Clément Delafargue & MarcAntoine Perennou using the awesome shellcheck.

Quentin ADAM

Written by

CEO @clever_cloud PaaS cloud computing company. We industrialize IT management to help developer to be happy and efficient and make organizations move fast.

Quentin ADAM

Written by

CEO @clever_cloud PaaS cloud computing company. We industrialize IT management to help developer to be happy and efficient and make organizations move fast.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store