If you often make changes to your
~/.bashrc, you might be sick of typing
source ~/.bashrc after every change.
It can also be annoying when you switch to a different tab in your terminal, but your new aliases or functions aren’t available until you type
While I was working on scm_breeze and my dotfiles repo, I grew tired of having to type this command, so I aliased it to
sbrc. But I knew I could do better, so I created an auto-reload script that reloads my
~/.bashrc if there are any changes to itself, or any of the files that it loads.
When you run it at the beginning of your
.bashrc, it wraps the
. commands with a function that builds an index of all the sourced files. At the end of your
.bashrc, you need to call the
finalize_auto_reload function, which:
auto_reload_bashrcfunction to your
Whenever you start a new line in your terminal, the
auto_reload_bashrc function reloads your
.bashrc if any of the sourced files have changed. Changes are detected by looking up the most recent modification time from all of the sourced files, and comparing that time with the previous value.
If you make a lot of changes to your
.zsh, you can check out my auto-reloading script here: