Code Monkey home page Code Monkey logo

bash-minifier's Introduction

NONFUNCTIONAL - No minification happens yet!

This mostly tokenizes shell scripts, but doesn't quite do that right. After tokenization, some level of parsing needs to happen in order to properly change the contexts. From there, I believe the best thing to do is to send data to another function that will minify the files.

This bloats a single shell script to consume at least (untested) 50x the memory of just holding the shell script in memory. That's because it tokenizes and adds a lot of metadata to each token. For example, take the classic fork bomb.

:(){:|:;};:

After tokenization, there's an array that looks like this example. The actual tokens may change in the future.

tokens=(
    'WORD,SOURCE.@1:1 :'
    'EMPTY_LIST,SOURCE.ARG.@1:2 ()'
    'BRACE_OPEN,SOURCE.ARG.@1:4 {'
    'WORD,BLOCK.@1:5 :'
    'UNKNOWN,BLOCK.ARG.@1:6 |'
    'WORD,BLOCK.ARG.@1:7 :;'
    'BRACE_CLOSE,BLOCK.ARG.@1:9 }'
    'WORD,SOURCE.ARG.@1:10 ;:'
    'EOL,SOURCE.ARG.@1:12 '$'\n'
)

When split by the delimiters (the first comma, at symbol, colon, and space), you get the following.

Token Context and Flags Line Col Data
WORD SOURCE. 1 1 :
EMPTY_LIST SOURCE.ARG. 1 2 ()
BRACE_OPEN SOURCE.ARG. 1 4 {
WORD BLOCK. 1 5 :
UNKNOWN BLOCK.ARG. 1 6 \
WORD BLOCK.ARG. 1 7 :;
BRACE_CLOSE BLOCK.ARG. 1 9 }
WORD SOURCE.ARG. 1 10 ;:
EOL SOURCE.ARG. 1 12 $'\n'

bash-minifier's People

Contributors

fidian avatar

Watchers

 avatar  avatar

Forkers

daneros

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.