What's New in Command-Line MiniScript v1.2
Tags: miniscript, commandline, programming, scripting
Published: 2023-02-09 01:23:39

This week saw the release of version 1.6 of the MiniScript language, as described [here](https://dev.to/joestrout/miniscript-16-now-available-fc7) a couple days ago.  But it also came with an update to command-line MiniScript, with some significant new features of its own.

The biggest and most obvious change is that command-line MiniScript now supports the [`import` command](https://miniscript.org/wiki/Import), just like Mini Micro.  This loads another script, located by name among an ordered set of import module directories, and makes any file-level variables in that module available to the main script.  For example, MiniScript has no built-in "distance" function, but the new _mathUtil_ module does:

```
MiniScript 
Command-Line (Unix) v1.1; language v1.6.0 (Feb  5 2023)
> import "mathUtil"
> mathUtil.distance([1,5], [10,7])
9.219544
```

Command-line MiniScript now comes with 11 standard import modules:

- **dateTime**: functions for getting the current time/date, and manipulating times and dates, including conversion to/from strings
- **grfon**: converts data to and from the [GRFON](https://luminaryapps.com/blog/announcing-grfon-a-kinder-gentler-serialization-format/) serialization format (sort of like JSON, but more compact and human-friendly)
- **json**: converts data to and from JSON format
- **listUtil**: dozens list-related utilities and extension methods
- **mapUtil**: a dozen utility functions related to maps (dictionaries)
- **mathUtil**: mathematical functions and constants
- **matrixUtil**: functions to do matrix math with 2D arrays
- **qa**: "quality assurance" module, providing methods like `qa.assert`
- **stringUtil**: a large selection of string manipulation methods, including [fill and match](https://luminaryapps.com/blog/ms-fill-match/) 
- **tsv**: converts data to and from Tab-Separated Value format
- **vt**: provides VTxxx escape codes for controlling colors, cursor position, and font in a terminal window

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y3v0xd55ysx1lbyjipge.gif)

The new `import` function will search for a module, by default, first in a _lib_ folder next to the script, then in a _lib_ folder next to the executable.  The standard installation would keep these official modules, plus any custom modules you want to be always available, in the folder next to the executable; and then create project-specific include modules in the project's _lib_ folder.  But you can arrange them however you like, using the **MS_IMPORT_PATH** environment variable to control where MiniScript looks.

All this is functionality that [Mini Micro](https://miniscript.org/MiniMicro) users have taken for granted, but until this 1.2 update, command-line MiniScripts had to be contained entirely in one file, and there was no simple way to get access to these standard libraries.  This is a real game-changer!  Now, not only can you benefit from the standard modules, but you can also break your large projects up into neat, self-contained modules called by the main program.

Now that this capability is there, I hope we'll start to see all sorts of creative and interesting import modules written by the user community.  How about one to generate SVG or PDF files?  Or one for stats and data analysis?  How about something to simplify [CGI programming](https://luminaryapps.com/blog/miniscript-cgi/)?  Or even something as simple as a log module, that neatly manages the proliferation of log files that results?

The possibilities are endless.  I can't wait to see what you dream up!