Skip to main content

A (toy) language that compiles to bash.

Project description

Compatibility Implementations Format Downloads

A (toy) language that compiles to bash. You can think of bashup as just a little syntactic sugar sprinkled on top of bash; any valid bash script is also a valid bashup script.

Just a spoonful of sugar makes the bashisms go down…

#!/bin/bash

@fn hi greeting='Hello', target {
    echo "${greeting}, ${target}!"
}

hi --target='World'

Installation:

$ pip install bashup

Compile and run the above example:

$ bashup -i above_example.bashup -o above_example.sh
$ bash above_example.sh
Hello, World!

Or just run it directly:

$ bashup -r above_example.bashup
Hello, World!

Compiled code (above_example.sh):

#!/bin/bash

#
# usage: hi [--greeting=<GREETING>] --target=<TARGET> [ARGS]
#
hi() {
    local greeting='Hello'
    local target
    local target__set=0
    local args=()

    while (( $# )); do
        if [[ "${1}" == --greeting=* ]]; then
            greeting=${1#--greeting=}
        elif [[ "${1}" == --target=* ]]; then
            target=${1#--target=}
            target__set=1
        else
            args+=("${1}")
        fi
        shift
    done

    if ! (( target__set )); then
        echo "[ERROR] The --target parameter must be given."
        return 1
    fi

    __hi "${greeting}" "${target}" "${args[@]}"
}

__hi() {
    local greeting=${1}
    local target=${2}
    shift 2

    echo "${greeting}, ${target}!"
}

hi --target='World'

Supported Bash Versions

The generated bash code works with bash 3.1 and above (tested against 3.1 to 4.3).

Nifty Features

Bashup tries its best to match the indentation of its compiled code against your hand-written bash. For example:

@fn hi greeting='Hello', target {
  echo "${greeting}, ${target}!"
}

…compiles to:

#
# usage: hi [--greeting=<GREETING>] --target=<TARGET> [ARGS]
#
hi() {
  local greeting='Hello'
  local target
  local target__set=0
  local args=()

  while (( $# )); do
    if [[ "${1}" == --greeting=* ]; then
      greeting=${1#--greeting=}
      ...

Planned Improvements

See this document for planned features.

Changelog

2.0.2

  • Fixed PyPI release.

2.0.1

2.0.0

1.1.2

1.1.1

  • Tweaked the README.

1.1.0

1.0.0

  • Initial release, supports @fn syntax.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bashup-2.0.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

bashup-2.0.2-py2.py3-none-any.whl (7.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file bashup-2.0.2.tar.gz.

File metadata

  • Download URL: bashup-2.0.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bashup-2.0.2.tar.gz
Algorithm Hash digest
SHA256 b433fda415e76f8ac0c86fbb5389f5b67cccccbaaf301a39b6ed191c2dfd6c7e
MD5 4d2da082551bb42d9d3fa894ba5160a7
BLAKE2b-256 311d8aee7145db8d5bc19016c407dd7e2d6fc3f9dc162f7c5d821b8b9c07d25f

See more details on using hashes here.

File details

Details for the file bashup-2.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for bashup-2.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3ffa2b723f78e5eda159bea8a67ebb99215600df299b8a03b86cffa9aff5506a
MD5 bac1bcc78bb28e6b5c4c81c9d41dd4d2
BLAKE2b-256 4ba587d43661f2c273ca5e7e92190dc90fc403db91fe2fd65bdf26adf3ef4923

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page