https://github.com/0komo/bash-source
Improve Bash's `source` into more modular system.
https://github.com/0komo/bash-source
bash bash-script module-system
Last synced: 4 months ago
JSON representation
Improve Bash's `source` into more modular system.
- Host: GitHub
- URL: https://github.com/0komo/bash-source
- Owner: 0komo
- License: mit
- Created: 2023-05-20T02:27:50.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-05-23T21:05:53.000Z (over 2 years ago)
- Last Synced: 2025-04-22T14:43:49.737Z (10 months ago)
- Topics: bash, bash-script, module-system
- Language: Shell
- Homepage: https://urnightmaree.github.io/bash-source/
- Size: 2.64 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bash-source
Improve Bash's `source` into more modular system.
## Why?
Bash's module system is so limited yet confusing, so I made this to cover Bash's module system problems by adding features that is already available in modern languages' module system.
How to use it?, it's very simple. Imagine that you have a `module.sh` in other directory, but you don't want to hardcode and type long path just to source it. This script helps you with that.
```bash
# /path/to/dir/module.sh
mod() {
echo "Hello world!"
}
MOD="Hi Mom!"
```
```bash
# /path/to/main.sh
source source.sh # patch `source` and `.`
# SOURCE_PATH is an array containing paths where script/package
# will be find
SOURCE_PATH+=("/path/to/dir/%s")
source module.sh # loaded!
mod
echo "$MOD"
```
```bash
# output
Hello World!
Hi Mom!
```
## Features
- Custom path search and path searcher.
- Compatible with built-in `source`.
- Easy-to-setup inside new projects or already projects.
## Installation
Drop [source.sh](/source.sh) into your project and source it.
```bash
source source.sh
```
You can also patch to it to all Bash script by setting up `BASH_ENV` environment variable into the path where [source.sh](/source.sh) is placed, no need to source it again.
```bash
export BASH_ENV="/path/to/source.sh"
```
To verify if it's working, put `source` into your script. The output should be like this.
```
source: error: script name is required
```
## License
bash-source is licensed under MIT license, see [LICENSE](/LICENSE) for more details.