Extended shell linker
Find a file
2021-01-06 16:46:43 +01:00
include restructure struc object extensions 2021-01-06 16:37:08 +01:00
src Remove trailing space on empty commands 2021-01-06 16:46:43 +01:00
.gitignore Ignore generated version header 2020-11-14 17:33:38 +01:00
generate_version.sh Add version tag for debug build 2020-11-14 18:24:47 +01:00
LICENSE Initial commit 2020-08-28 10:46:02 +02:00
Makefile first debashify implementation: replace &> and >& redirects 2021-01-06 11:10:45 +01:00
README.md first debashify implementation: replace &> and >& redirects 2021-01-06 11:10:45 +01:00

lxsh

Extended shell linker for linking, processing and minimizing shell code

Installing

linux-amd64

Download the lxsh-linux-amd64.tar.gz archive, extract it, and move lxsh binary in a PATH folder (/usr/local/bin is the recommended).

Other

See Build.

Features

Command extensions

lxsh implements special linking commands that are resolved at linking. These commands can be placed anywhere within the script like regular commands.

  • %include : allows to insert file contents
  • %resolve : allows to execute a shell command and insert its output

See lxsh --help-commands for more details

Minimize code

Reduce code size to a minimum without changing functionality with the -m option.

Further minimizing

The script can be further minimized by altering code elements. This can cause some change in execution behavior if you are not careful.

Variable names can be minimized with --minimize-var, use --exclude-var to exclude variables from being minimized (for example environment config).

Function names can be minimized with --minimize-fct, use --exclude-fct to exclude functions from being minimized.

Unused functions and variables can be removed with --remove-unused.

Other features

Output generated code

By default lxsh outputs generated shell code to stdout. You can use the -o option to output to a file and make this file directly executable.

The resulting script is not dependent on lxsh

Live execution

Directly execute an extended lxsh script with either

  • -e option
  • shebang is lxsh

Direct execution introduces direct dependency on lxsh and code generation overhead, therefore it should be avoided outside of development use

There may be some issues with direct execution as of now

Variable/Function/command listing

You can list all calls of variables, functions or commands with --list-* options

Build

Dependencies

Depends on ztd

Building

Use make -j8 to build.
You can use environment variables to alter some aspects:

  • DEBUG: when set to true will generate a debug binary with profiling
  • RELEASE: when set to true, the version string will be generated for release format
  • STATIC: when set to true will statically link libraries

Work in progress

The full POSIX syntax is supported and should produce a functioning result.
However not all bash syntax is supported yet.

incomplete POSIX features

  • $(()) arithmetics are not minimized
  • Variables in $(()) arithmetics are not accounted for in variable processing

Known bash issues

  • &> and >& are not supported
  • |& is not supported
  • <<< is not supported
  • <() is not supported
  • ${!VAR} does not register as a variable
  • Extended globs (*()) are not supported
  • (()) creates two subshells instead of one object
  • Unsetting functions will not work properly when minimizing variables or functions

Debashifying

Work to debashify scripts is planned