Skip to content

emanuelbuholzer/bash-inline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bash-inline

Introduction

bash-inline is a CLI tool to format Bash scripts for inlining.

Usage

In order to format a Bash script to be readable you can run bash-inline without any further paramters. By default bash-inline reads your Bash script from standard input to standard output.

Given a Bash script like this:

#!/usr/bin/env bash
echo "Is true just 1?"
# We'll see
if [[ true -eq 1 ]]; then
  echo "True is really just 1"
fi

Running bash-inline on it will remove comments, format (e.g. add missing semicolons) and check your script, such that it can be inlined:

echo "Is true just 1?";
if [[ true -eq 1 ]]; then
  echo "True is really just 1";
fi;

You can also use this tool to expand a one-liner and make it more readable. The general usage is:

cat script.sh | bash-inline

The same script can also be one-lined when passing the -1 flag:

echo "Is true just 1?"; if [[ true -eq 1 ]]; then echo "True is really just 1"; fi;

The general usage for creating a one-liner is:

cat script.sh | bash-inline -1

You can also read and output the Bash script from a file, and pass some arguments for formatting it given some line length and ribbon ratio constraints. For more information on how to use bash-inline run bash-inline --help.

Building

This project is built with GHC and cabal-install, you can get the latest version by using GHCup.

Update dependencies and configure the project with tests enabled:

cabal update 
cabal build --only-dependencies --enable-tests --enable-benchmarks

Build the project and run tests:

cabal build --enable-tests --enable-benchmarks all
cabal test all

If you want to install the latest version of bash-inline:

# Be sure that the $CABALDIR/bin directory is in your path
cabal install

Special thanks

To everyone who contributed to language-bash and pretty which provide the core functionality to this tool.

About

Bash script formatting for inlining

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published