Skip to content
gatsh is a simple shell script to compile multiple shell scripts into a single one
Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Rename file May 28, 2019
.gitignore Add initial files 🎉 Apr 3, 2019
.gitmodules Add first tests Apr 27, 2019
LICENSE Initial commit Apr 3, 2019
README.md Rename file May 28, 2019
gatsh Remove some todos May 28, 2019

README.md

Gatsh

Recursively inline files required by your scripts


What is this?

Gatsh parses your script files for references to other scripts and inlines the contents of those. The idea is to allow people to split their shell scripts into multiple files while still giving them the possibility to distribute a single file.

Let's say you have a file root.sh that references a bunch of other files like logger.sh and colors.sh:

# root.sh
source lib/logger.sh

log "Hello World!"

# lib/logger.sh
source colors.sh

log()  {
  local message=$1
  echo "${GREEN}[INFO]${DEFAULT} $message"
}

# lib/colors.sh
DEFAULT="\e[39m"
RED="\e[31m"
GREEN="\e[32m"

Running gatsh root.sh will inline source imports and yield:

# root.sh
DEFAULT="\e[39m"
RED="\e[31m"
GREEN="\e[32m"

log()  {
  local message=$1
  echo "${GREEN}[INFO]${DEFAULT} $message"
}

log "Hello World!"

Installation

Download the latest version from Gatsh from the releases page or get the latest version.

wget https://raw.githubusercontent.com/hschne/gatsh/master/gatsh && chmod +x gatsh

Add Gatsh to your path to make it available from any location.

Usage

Usage is straight forward - simply run

gatsh infile.sh > infile_gatsh.sh

to concatinate infile.sh and all its dependencies. Gatsh supports the following options:

-o|--outfile  Redirects the output to the specified file
-h|--help     Displays the help dialog

Development

Testing

Gatsh uses bats-core for tests. Additionally, a number of extension for bats are in use.

In order to run the tests you must first initialize the extension submodules.

git submodule init
git submodule update

Bats features both system tests, which verify that the whole script works, and unit tests, which verify specific functions. You can run both using

bats test/gatsh.bats # System tests, use test files
bats test/unit.bats # Individual function tests

System tests rely on a number of files that can be found in tests/files.

License

MIT (c) @hschne

You can’t perform that action at this time.