Note: The setup described in the following sections can be applied to shells like bash, zsh, fish and other common unix shells. However, keep in mind that the command(s) might differ a bit.

I’m using custom shell commands, aliases, and functions quite heavily. As my .bashrc and zshrc grew too big, I decided to mudularise my config and want to share with you how I’ve done it. First of all, I’ve created a dedicated directory in my root directory for all of my custom shell commands, aliases, and functions:

$ mkdir ~/.shell_config

Inside of the directory I created dedicated files per topic. My current .shell_config directory looks like this:

$ tree ~/.shell_config
/home/florian/.shell_config
├── application_aliases
├── directory_aliases
├── enhanced_shell_commands
└── git_aliases

0 directories, 4 files

The definition of one of these files is pretty straightforward:

$ cat ~/.shell_config/application_aliases
alias python3.9="/home/florian/workspace/python/cpython/python"
alias python="python3.8"
alias open="xdg-open"

alias build_latest_python="cd /home/florian/workspace/python/cpython && git pull && make && make test"

function pycharm() {
    /usr/local/bin/pycharm-2019.2.3/bin/pycharm.sh "$1" </dev/null &>/dev/null &
}

Finally, add the following line to your .bashrc , .zshrc or whatever your shell config file is called to automatically load all files inside the .shell_config directory:

for f in ~/.shell_config/*; do source $f; done

And that’s it! Congratulations, you’ve modularised your shell config! If you want to get a list of useful unix commands, aliases and functions I’m currently using, visit my useful-unix repository over at GitHub. Stay curious and keep coding!


This post was originally published to Medium.