stank icon indicating copy to clipboard operation
stank copied to clipboard

leanify

Open mcandre opened this issue 8 years ago • 0 comments

As an engineer, I want stank to help me reduce the size of my shell scripts, so that I can transfer scripts more quickly.

Offer a new command line application, leanify, to generate *.min.sh scripts from POSIX-compliant shell scripts, that feature a reduced number of characters. Use the mdvan/sh lib to parse shell scripts into an AST, then emit a reduced version to a *.min.sh file.

  • [ ] Strip out comments.
  • [ ] Reduce line breaks to semi-colons (;), though keep the final EOL newline for POSIX compliance.
  • [ ] Remove trailing backslashes (\) that are syntactically redundant, in particular ^*;(\w)*\\$ and ^*&&(\w)*\\$. In contrast, each critical backslashe, such as for continuing the same shell statement, should be reduced, along with its line break, to a single space.
  • [ ] Reduce extraneous whitespace generally.
  • [ ] Reduce un-interpolated string constants to either raw un-quoted (...), or single-quoted ('...'), or double-quoted ("...") format, depending on which format features the minimal number of characters in the literal.
  • [ ] Rebind un-exported bindings to shorter variable names.

mcandre avatar Dec 29 '17 19:12 mcandre