Script Compression - xsc/bashing GitHub Wiki

This feature is experimental!

An interesting feature in Bashing is script compression. Use the flag --compress with uberbash to generate a script that extracts itself on every call, providing a certain runtime overhead whilst not taking up as much space as the plain-text version (in our case 612 vs. 1109 bytes):

$ bashing uberbash --compress
Creating /git/public/shell/greet/target/greet-0.1.0-SNAPSHOT.sh ...
Uberbash created successfully.
Compressing into /git/public/shell/greet/target/greet-0.1.0-SNAPSHOT.gz.sh ...
Uberbash (compressed) created successfully.

$ cat target/greet-0.1.0-SNAPSHOT.gz.sh
#!/bin/bash
tail -n +3 "$0" | gzip -d -n 2> /dev/null | bash -s "$@"; exit $?
# .... gzipped data ....

$ .target/greet-0.1.0-SNAPSHOT.gz.sh hello "World"
Hello, World!

Be aware that this will break everything relying on the variable $0 since it will be set to bash and not the actual path of the script! Bashing itself can be compressed, too, resulting in e.g. a 72% size reduction with version 0.1.3:

$ du -b ~/.bin/bashing target/bashing-0.1.3.sh 
15946	/home/yannick/.bin/bashing
4541	target/bashing-0.1.3.sh