Skip to content

0komo/bash-source

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

# /path/to/dir/module.sh

mod() {
    echo "Hello world!"
}

MOD="Hi Mom!"
# /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"
# 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 into your project and source it.

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 is placed, no need to source it again.

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 for more details.

About

Improve Bash's `source` into more modular system.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages