From 0eb28cf6cca98c50cc920c9a79700d288febcaa2 Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Sun, 24 Mar 2024 09:50:29 +0100 Subject: [PATCH] added ability to dynamically source files from file in home directory added explanation and example in README.md --- README.md | 16 ++++++++++++++++ bashrc_overrides/_all | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 1ad5f13..6d996b4 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,19 @@ Explaining section for not-so-intuitive configurations - alias `sambaserver`: (¡requires Docker!) please `cd` into the directoy is needed to be shared and execute `sambaserver`, then just login with default username `user` and the default password `P4ssw0rd` with the host computer as URL/IP, autodiscovery of both the host and the share was tested working on Windows and a Samsung Tablet. - alias `sambastop`: (¡requires Docker!) when you're finished, this command stops and removes the samba container. - alias `termbin`: (¡requires Netcat!) use when piping a cat/echo/file/etc to upload to termbin.com + +## Modular sourcing mechanism +Create a file in your home directory called `~/.bash_sources`, and put a script path on every line of this file, it will be sourced automatically.
+WARNING: it has to be a full path, for example `/path/to/script.sh` and not abbreviated (as in `~/script.sh`)... idk bash decided like so.
+WARNING 2: every line needs to be a path to a file, not a direct command, sourcing a file is possible; souring an "export" or a function... not so much! + +#### For example: +`/home/user/.bash_sources`: +```bash +/home/user/.bash_path +/path/to/some/other/script.sh +``` +`/home/user/.bash_path`: +```bash +export PATH=~/bin/myproject/bin:$PATH +``` diff --git a/bashrc_overrides/_all b/bashrc_overrides/_all index fd8cc54..de7f535 100644 --- a/bashrc_overrides/_all +++ b/bashrc_overrides/_all @@ -1,4 +1,15 @@ +# Source all the overrides in this folder for source in $(find "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" -type f | grep -Ev "_all|terminal_fancyfying"); do . "${source}" done . "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/terminal_fancyfying_${TERMINAL_FANCYFY}" + +# If the file ~/.bash_sources exist, source every line it contains +if [ -f ~/.bash_sources ]; then + while IFS= read -r line; do + # Skip empty lines and comments (#) + if [ -n "$line" ] && ! [[ "$line" == \#* ]]; then + . "$line" + fi + done < ~/.bash_sources +fi