"oliosource" is a simple shell script that merges "sourced" shell scripts as a single script for your convenient distribution.
In other words, " . ./foo.sh
" or " source ./foo.sh
" lines in a shell script get replaced with the content of " ./foo.sh
" without the shebang.
oliosource /path/to/target/main.sh
- Note
- If
shfmt
is installed then it will format the output as well. - Runs on POSIX compatible shells.
- Tested on latest macOS and Linux(Ubuntu).
- If
Grouping the frequently used functions in other files and import or source them eliminates duplicate code and reduces the size of a script for better visibility and maintenance.
Even though we like this approach, we felt distributing as a single script is much convenient for the users to download.
To solve this problem, "oliosource" is our rough draft to merge the "sourced" scripts into one file. It simply replaces the " .
" or " source
" line to the source file's content without the shebang
and nothing more.
Any contribution for the better is welcome!
$ cat ./path/to/main_script.sh
#!/bin/bash
# shellcheck disable=SC1091
. ./parrotry.sh
if [ 0 = $# ]; then
echo >&2 "argument missing"
exit 1
fi
parrotry "$@"
$ cat ./path/to/parrotry.sh
#!/bin/bash
# parrotry echoes the given args to STDOUT
parrotry() {
echo "$@"
}
$ # Let's run!!
$ oliosource ./path/to/main_script.sh
#!/bin/bash
# parrotry echoes the given args to STDOUT
parrotry() {
echo "$@"
}
if [ 0 = $# ]; then
echo >&2 "argument missing"
exit 1
fi
parrotry "$@"
- Download Raw Source: https://git.io/oliosource
curl -sL https://git.io/oliosource
- To install the script, place it in any path at
$PATH
env variable andchmod +x
to give access.
# Sample to install OlioSource under /usr/local/bin
# (you may need sudo to chmod and mv)
curl -sL https://git.io/oliosource > oliosource && \
chmod +x oliosource && \
mv ./oliosource /usr/local/bin
- Issues and PRs may be in Japanese, Spanish or English.
- Providing a test that reproduces the failure in the issue will help us a lot.
- MIT
- Copyright (c) The OlioSource Contributors