Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created May 7, 2012 02:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/2625442 to your computer and use it in GitHub Desktop.
Save thinkerbot/2625442 to your computer and use it in GitHub Desktop.
A shell script transpiler

Provides a mechanism to write portable shell scripts in a higher-level language.

Ruby may be used to describe shell scripts in code. For example shell commands may be represented as methods and command pipelines as method chains. The method calls are translated into shell script. Zero or more script files may be generated in this process.

Cursor objects can be used to mark the locations in the final script where a given shell expression is to be added. For example one cursor could mark where options are defined in a 'getopts' command, another could mark where the option actions are written, and a third where the defaults are set. With these marks an 'Options' object in ruby could translate method calls into modifications in all the relevant locations.

Modules may be used to override methods to output shell script tailored to specific targets, for example ksh vs bash or apt vs rpm.

Much of the transpiler syntax is prototyped on various branches of the Linecook and Linebook projects. A document class capable of issuing multiple cursors has not been implemented. See:

Other programming languages may also be transpiled in this way. For example PLSQL could be combined with a ruby-sql library (ex Arel) to write PLSQL code. Much of the code (ex the cursor document, the surrounding programs) could be reused although the actual transpiling methods would naturally be different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment