A (toy) language that compiles to bash.
Project description
A (toy) language that compiles to bash.
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!
Compiled code (above_example.sh):
#/bin/bash
#
# usage: hi [--greeting <GREETING>] --target <TARGET> [ARGS]
#
function hi() {
local greeting='Hello'
local target
local target__set=0
local args=()
local i
for ((i = 1; i < $#; i++)); do
if [ "${!i}" == "--greeting" ]; then
((i++))
greeting=${!i}
elif [ "${!i}" == "--target" ]; then
((i++))
target=${!i}
target__set=1
else
args+=("${!i}")
fi
done
if [ ${target__set} -eq 0 ]; then
echo "[ERROR] The --target parameter must be given."
return 1
fi
__hi "${greeting}" "${target}" "${args[@]}"
}
function __hi() {
local greeting=${1}
local target=${2}
shift 2
echo "${greeting}, ${target}!"
}
hi --target 'World'
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]
#
function hi() {
local greeting='Hello'
local target
local target__set=0
local args=()
local i
for ((i = 1; i < $#; i++)); do
if [ "${!i}" == "--greeting" ]; then
((i++))
greeting=${!i}
...
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-1.0.0.tar.gz
(6.0 kB
view hashes)
Built Distribution
Close
Hashes for bashup-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02eee2a65f2f1c958880d4160e74341411c355362fe3a0971d7d1fbb38c99edd |
|
MD5 | 0237e34840da04de5c27474e05ed2af1 |
|
BLAKE2b-256 | 4444bc1e80b35e7adb80ae7633c665ba82ac4a053376a77fc8da9632c5d6a3e3 |