An open API service indexing awesome lists of open source software.

https://github.com/hschne/gatsh

gatsh is a simple shell script to compile multiple shell scripts into a single one
https://github.com/hschne/gatsh

bash bash-script

Last synced: about 2 months ago
JSON representation

gatsh is a simple shell script to compile multiple shell scripts into a single one

Awesome Lists containing this project

README

          

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`:

```bash
# 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:

```bash
# 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](https://github.com/bats-core/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

```bash
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](LICENSE) (c) [@hschne](https://github.com/hschne)