voila 2.0.0

A tool for doing complex operations to files and directories.
Documentation

Voila forthebadge forthebadge

Contributor Covenant GitHub license Lines of code GitHub release (latest SemVer) GitHub commits since latest release (by date) GitHub Release Date GitHub last commit GitHub contributors OSS Lifecycle Crates.io Crates.io (latest) Linux build macOS build Windows build

Voila is a domain-specific language designed for doing complex operations to folders & files. It is based on a CLI tool, although you can write your Voila code and do something like this voila DIRECTORY "$(cat operations.vla)". Voila is mainly tested in Linux, so should work better in *nix (Linux,*BSD, macOS, etc) than in Windows-based operating systems, but shouldn't be any problems on them.

Syntax

$ voila DIRECTORY '<@VARIABLE | STRING> OPERATOR <@VARIABLE | STRING> [|| | && ANOTHER_CONDITIONAL ...] {OPERATION1-CYCLE-1(ARG1 ARG1, ARG2) OPERATION2-CYCLE-1(ARG1 ARG2) ...; OPERATION1-CYCLE-2(ARG1, ARG2 ARG2, ARG3)...}'

Voila's syntax is composed of a traditional conditional/multi-conditional statement, followed by the operations, delimited within curly brackets. These are separated into cycles. A cycle is an iteration between all directory files, the operations in every cycle are executed in parallel, and cycles are executed consecutively. cycles are separated with ;, and operations/functions arguments are separated with ,. Variables' prefix is @, and its value changes to the file that is evaluating. For a more intuitive explanation, go to the "Examples" section.

These are the available conditional operators:

  • ==: true if the first value matches the second
  • !=: true if the first value doesn't match the second
  • >: true if the first value is greater than the second
  • >=: true if the first value is equal or greater than the second
  • <: true if the first value is less than the second
  • <=: true if the first value is equal or less than the second
  • ~=: true if the a value matches the regex provided in the other value
  • ~!: true if the a value doesn't match the regex provided in the other value

These are the available variables:

  • name: filename
  • path: absolute path
  • parent: absolute path to file's directory
  • ownerID: file owner ID (unix-only)
  • empty: true if the file size is less than 1 byte (else false)
  • readonly: true if the file is ro (else false)
  • elf: true if the file is compliant to the Executable & Linkable Format (else false)
  • txt: true if the file is a valid text file (else false)
  • hidden: true if the file is hidden (else false)
  • size=tb: file size in terabytes
  • size=gb: file size in gigabytes
  • size=mb: file size in megabytes
  • size=kb: file size in kilobytes
  • size=bs: file size bytes (no decimals)
  • sum=md5: md5 checksum this variable might be removed in the future, md5 is completely broken
  • sum=sha1: sha1 checksum this variable might be removed in the future, sha1 is completely broken
  • sum=sha224: sha224 checksum
  • sum=sha256: sha256 checksum
  • sum=sha384: sha384 checksum
  • sum=sha512: sha256 checksum
  • creation=date: date of file creation (yyyy-mm-dd)
  • creation=hour: hour of file creation (hh:mm:ss)
  • lastChange=date: date of the last modification to the file (yyyy-mm-dd)
  • lastChange=hour: hour of the last modification to the file (hh:mm:ss)
  • lastAccess=date: date of the last access to the file (yyyy-mm-dd)
  • lastAccess=hour: hour of the last access to the file (hh:mm:ss)

These are the available operations/functions:

  • print: prints something to the terminal (not to the printer lol)
  • create: creates a file, with its content as second argument
  • mkdir: cretes a folder/directory
  • delete: deletes file/directory ⚠️
  • move: moves a file or a folder/directory ⚠️
  • copy: copies a file or a folder/directory
  • gzc: compress file using gzip. first argument is the file to compress, the second is the file to save the compressed file
  • gzd: decompress file using gzip. first argument is the file to compress, the second is be file to save the compressed file
  • shell: gives a command to the Bourne Shell (sh) in Unix systems (like Linux or macOS), and a command to PowerShell (powershell) in Windows systems. Exists for doing things Voila functions can't, for example, send a dbus message. ⚠️

⚠️ WARNING: If you use functions that access and/or modify the same file/directory in the same cycle it could cause undefined behavior because the file would be accessed and overwritten at the same time. For avoiding that, consider splitting those functions into different cycles. A workaround is being discussed in #5

forthebadge

Examples

  • voila /backup "@creation=date <= 2020-01-01 { print(@name has been deleted) delete(@path) }: Voila will delete every file in /backup whose creation was earlier to 2020 printing a delete message.
  • voila /backup "@name ~= (.*)-2020 { print(@name has been deleted) delete(@path) }: Voila will delete every file in /backup ending in 2020 printing a delete message.
  • voila /something "@sum=md5 == 308uyrp028y4hp079y2hv92gbf49 { mkdir(./sums); create(./sums/@name.sum, @sum=sha256) }: Voila will create a folder in the current directory named "sums", will search for a file with that md5 checksum, get its sha256 checksum and save it in the sums folder.
  • voila /backup "@size=gb >= 1 { print(@name has been deleted) delete(@path) }: Voila will delete every file in /backup weighter than 1gb printing a delete message.

CLI flags

  • -r, --recursive: If provided, voila will be executed recursively, which means that will also affect the files in the folders of the directory provided.
  • -h, --help: Displays help.
  • -v, --version: Displays installed version of Voila, if any.

Installation

You can install voila by cloning the repository and compiling or by cargo install voila. I have planned to provide prebuilt binaries soon.

Submitting