Skip to content

Repository files navigation

XYLITOL

Add cleanliness and freshness to your shell scripts.

XYLITOL plays a role similar to gum, but since it's written in Amber,
it doesn't depend on external binaries and remains fully portable.

Execution

Just download and execute xylitol.sh script. (Bash 3.2+ is required.)
ANSI support is required for the terminal.

or use Amber to compile Bash script from amber code.

bash <(curl -sL "https://github.com/amber-lang/amber/releases/download/0.6.0-alpha/install.sh")
tools/build.sh

Usage

From a Bash script

Source xylitol.sh in your script, app.sh:

#!/usr/bin/env bash
source ./xylitol.sh

name=$(xylitol input --header="Project name")
kind=$(printf 'lib\nbin\n' | xylitol choose --header="Kind")

if xylitol confirm --header="Create $name as a $kind?"; then
    echo "creating $name"
fi

Bundle it into a single file to ship:

tools/bundle.sh app.sh > app-standalone.sh
./app-standalone.sh

From an Amber script

Vendor this repository and import from src/lib.ab:

git submodule add https://github.com/zlfn/xylitol.git vendor/xylitol
import { xyl_choose, xyl_confirm } from "vendor/xylitol/src/lib.ab"

main {
    const env = xyl_choose(["dev", "staging", "prod"])
    if xyl_confirm("Deploy to {env}?") {
        echo("deploying to {env}")
    }
}

Commands

  • choose: Choose an option from a list of choices
  • filter: Pick from a list narrowed by typing
  • input: Prompt the user for input.
  • confirm: Prompt the user for confirmation (yes/no).
  • file: Pick a file from system.

Choose

Choose an option from a list of choices

choose
cat songs.txt | ./xylitol.sh choose
cat foods.txt | ./xylitol.sh choose --header="Grocery Shopping"

Filter

Pick from a list narrowed by typing.

filter
cat cards.txt | ./xylitol.sh filter
ls | ./xylitol.sh filter --no-limit --height=15

Input

Prompt for input with a simple command.

input
./xylitol.sh input > answer.txt
./xylitol.sh input --prompt="Enter password: " --password > password.txt

Confirm

Prompt the user for confirmation (yes/no).

confirm
./xylitol.sh confirm && rm file.txt || echo "File not removed"

File

Prompt the user to select a file from the file tree.

file
./xylitol.sh file ~/.config

Tested on

Every push drives the built script through a pseudo terminal on:

- Ubuntu / docker bash 3.2, 4.0, 4.3, 4.4, 5.0, 5.2
- macOS / /bin/bash (3.2)

About

Add freshness to your shell scripts.

Topics

Resources

Contributing

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages