Coder Social home page Coder Social logo

πŸ‘» Spook in the Shell πŸ‘» (Spit-sh) Build Status

Spook in the Shell (Spit or Spit-sh) is a language/compiler that outputs shell scripts. It compiles a strongly typed Perl 6 like language called "Spook" into /bin/sh compatible scripts. It's main purpose is devops/infrastructure related tasks. Current features include:

  • Compile time type checking
  • Basic libraries/modules
  • Test module for outputting TAP
  • Useful builtin classes and functions
  • Running and testing scripts in Docker
  • Logging to standard output

Everything about the language and compiler is still experimental. I am thinking about pivoting a bit into compiling golang to create standalone binaries instead of shell scripts. πŸ€”

Example

To get an idea of what Spit is consider the following basic program:

.install unless Pkg<nc>; # install nc unless it's already there
ok Cmd<nc>,"nc command exists now"; # test the nc command is there

You can compile this for CentOS from the command line like:

spit eval --os=centos  '.install unless Pkg<nc>; ok Cmd<nc>,"nc command exists now"'

Which ouputs the following shell at the time of writing:

BEGIN(){
  e(){ printf %s "$1"; }
  exec 4>/dev/null
  installed(){ yum list installed "$1" >&4 2>&4; }
  install(){ yum install -y $1 >&4 2>&4; }
  exists(){ command -v "$1" >&4; }
  exec 3>&1
  say(){ printf '%s\n' "$1" >&3; }
  note(){ printf '%s\n' "$1" >&2; }
  die(){ note "$1" && kill "-TERM" $$ >&4; }
  ok(){ test "$1" && say "βœ” - $2" || die "✘ - $2"; }
}
MAIN(){
  if ! installed nc; then
    install nc
  fi
  ok "$(exists nc && e 1)" 'nc command exists now'
}
BEGIN && MAIN

If you have docker installed you can test this with:

spit eval --in-docker=centos '.install unless Pkg<nc>; ok Cmd<nc>,"nc command exists now"'
βœ” - nc command exists now

Unfortunately on Debian the package is named 'netcat'. Let's deal with that:

# install-nc.sp
constant Pkg $nc = on {
    Debian { 'netcat' }
    Any    { 'nc' } # the default
};

.install unless $nc;
ok Cmd<nc>,"nc command exists now";

And now it should work on both the RHEL and Debian families of Linux distributions.

spit  compile install-nc.sp --in-docker=debian:latest
βœ” - nc command exists now

Install

Spit is written in Perl 6 and requires rakudo and something to install Perl 6 ecosystem modules with like zef.

zef install Spit

and run

spit eval 'say "hello world"'

To check it's working.

Documentation

The documentation is pretty useless at the moment because the tooling has fallen far behind the language. What exists is under: doc/.

Project Layout

  • The Perl 6 Spit compiler module is in lib
  • The actual Spit source code is under resources/src
  • The core spit modules are under resouces/core-lib
  • The spec tests are in spec.

spitsh's Projects

spitsh icon spitsh

πŸ‘»The Spook in the Shell🐚 compiler

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.