If you like KISS, there is a good chance you will enjoy this short article. I will show you how to structure projects wich use bash scripts.

Almost in any project there is the need to use bash scripts to automate work.

I convert any multi-line command or multi-argument command into a script.
It’s easier to type ./bin/run-docker.sh than to type/paste the full command, like this one, into the terminal:

docker run --name haproxy-routing \
           -p 80:80 \
           -v /home/user/config:/data/haproxy/config \
           --link site-container:site \
           --link blog-container:blog \
           -d czerasz/haproxy-routing

The convention I use, is to put all bash scripts into a bin directory inside of the project:

.
├── app.py
├── bin
│   └── ...
├── config
│   └── environment.yml
└──...

It’s very common that I reference to files from the project level. And it’s so common, that I always start my bash scripts with the following template:

1 #!/bin/bash
2 
3 script_directory="$( cd "$( dirname "$0" )" && pwd )"
4 project_directory=$script_directory/..

Thanks to a cool Sublime package called Fetch I can reuse this template by taking just two steps. You can reuse my Fetch config which looks like this:

{
    "files":
    {
        "bash_script_template": "https://gist.githubusercontent.com/czerasz/3046161/raw/3c2300338917de19045b5b9a500fa25cacb41297/start-script-helper.sh",
        ...
    }
}



There are projects mostly ruby based, where the bin directory is occupied by gems installed with the bundle binstrubs command:

bundle install --binstubs

In such cases I update my .gitignore with the following:

# Ignore all gems and track only wanted scripts
bin/*
!bin/build-docker.sh