hail

command module
v0.0.0-...-908e67b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README


Unit Tests Go Reference Releases Discord Discussion

hail

hail is a shell, written in pure Go, that runs bash scripts and replaces bash at the terminal. It uses no cgo and links no C library, and it builds with TinyGo.

hail ports much of brush, a bash written in Rust. It is also the full example of three xo packages: ox for the command line, rline for line editing, and transit for syntax highlighting.

hail colors a for loop and a pipeline in the style onedark as they are typed, runs them, and completes a command, a variable and a file name with Tab

Status

hail runs scripts, and gives an interactive shell with job control on Unix. It does not pass every test of brush yet. The design is in docs/DESIGN.md, and the order of the work is in docs/PLAN.md.

Building

Build hail with Go, with cgo turned off. hail uses no C code, but some of the packages that it uses import os/user, which links the C library when cgo is on. With CGO_ENABLED=0, the binary is static:

CGO_ENABLED=0 go build .

On Linux, and for WebAssembly, you can also build hail with TinyGo. TinyGo on macOS, Windows, FreeBSD and NetBSD is not supported (D30). Give TinyGo the flag -stack-size=8MB. Under TinyGo, each goroutine has a stack of fixed size, and hail needs 8 MB for a deep recursion in a pipeline stage (D28):

tinygo build -stack-size=8MB .

The texts of help in GNU bash are under the GPL, so a build of hail does not hold them, and help gives a short text of its own for each builtin. A build with the tag gnubash, run under the name bash, gives the texts of bash. CONTRIBUTING.md says how to make that build (D38).

Each release on GitHub holds a build of Go for Linux, macOS and Windows, on amd64 and arm64, and for FreeBSD and NetBSD on amd64. It also holds the builds of TinyGo for WASI and for the browser.

Goals

  • Run bash scripts, and give the output, the errors and the exit status that bash gives. The tests of brush and of GNU bash measure this.
  • Run natively on Linux, macOS, the BSDs and Windows, without MSYS or Cygwin.
  • Build with Go and with TinyGo, including WebAssembly with WASI.
  • Run in a web browser, so that a person can try hail from its documentation without installing it.
  • Give an interactive shell with editing, history, completion and colors, that reads the user's inputrc file.
  • Keep the binary small, start fast, and use little memory. hail measures these from the start, and works on them after the behavior is right.

Configuration

hail does not read ~/.bashrc or ~/.bash_profile. An interactive hail reads config.yaml from its configuration directory. A script that hail runs does not read it, so a script behaves the same on every machine:

Platform Directory
Linux and other Unix systems $XDG_CONFIG_HOME/hail, which is ~/.config/hail by default
macOS ~/Library/Application Support/hail
Windows %AppData%\hail

The file holds settings, and not code. A function goes in a bash script that the file names under source. Every key is optional:

prompt: '\u@\h:\w\$ '    # PS1
prompt2: '> '             # PS2
env:                      # variables to set and export
  EDITOR: vim
set: [noclobber]          # options of set -o
shopt: [globstar]         # options of shopt
aliases:
  ll: ls -l
history:
  file: ~/.local/state/hail/history   # HISTFILE
  size: 10000                         # HISTSIZE
  file_size: 20000                    # HISTFILESIZE
  control: [ignoreboth]               # HISTCONTROL
  ignore: [ls, bg]                    # HISTIGNORE
editor:
  vi: false               # edit in vi mode, as set -o vi does
  color: true             # color the line as you type it
  style: onedark          # the style of the colors, by name or path
  styles:                 # the style of a kind of word, over the style
    keyword: 'bold #c678dd'
  bindings:               # key bindings, as lines of an inputrc file
    - '"\C-o": "> output"'
    - 'set completion-ignore-case on'
    - 'set keymap vi-command'
    - '"z": end-of-line'
source:                   # scripts to run, relative to the directory of the file
  - functions.sh

--norc turns the file off. Set NO_COLOR to turn the colors off.

hail reads the user's inputrc file, as bash does, and then the lines of editor.bindings, as though they were one more inputrc file. A binding in config.yaml replaces a binding of the same keys in the inputrc file. Each line is a line that you can give to bind. Write each line in single quotes, so that YAML keeps each backslash. A set keymap line applies to the lines after it. The lines bind keys in the keymap of the editing mode until a line names another keymap, and vi: true applies first.

hail applies the settings in this order: env, the prompts and the history, set, shopt, aliases, editor.vi, editor.bindings, and then the scripts of source. A script can change what the keys above set, with bind and set -o.

Started under the name bash or sh, such as through a link, hail acts as bash does under that name. It reads the startup files of bash in place of config.yaml, and under sh it turns on POSIX mode. Under the name bash, a login shell reads /etc/profile and the first of ~/.bash_profile, ~/.bash_login and ~/.profile, and an interactive shell that is not a login shell reads ~/.bashrc. Under the name sh, a login shell reads /etc/profile and ~/.profile, and an interactive shell reads the file that $ENV names. Under both names, a login shell runs ~/.bash_logout when exit or logout ends it.

Started under the name rbash, or with -r, hail is a restricted shell, as bash is: it refuses cd, commands with a / in their names, changes to PATH, redirections of output and more, after the startup files. A restricted shell is not a sandbox. A program that it runs can start a shell without the restrictions (D39).

Styles

hail colors the line with a style of transit. A style gives a color and a font to each kind of word, such as a keyword, a string or a comment. hail bundles the 168 styles of transit, and the default style is onedark.

To choose a style, name it under editor.style in config.yaml:

editor:
  style: dracula

editor.style also takes the path of a style file. A style file is a JSON file in the form of the styles of transit. A relative path is relative to the directory of config.yaml. editor.styles changes the style of a kind of word, over the style. The kinds of word are comment, constant, embedded, function, keyword, number, operator, property and string. A value is a style of transit, such as 'bold #c678dd', or a style of rline, such as bold ansi-fuchsia. An empty value takes the color off. Put a value that holds # in quotes, because YAML starts a comment at #:

editor:
  style: ~/styles/mine.json
  styles:
    comment: 'italic #6272a4'
    keyword: bold ansi-fuchsia
    string: ''

If hail cannot find or read the style, it writes a warning when it starts, and uses onedark.

To list the styles, and to see a style before you choose it, run:

hail --list-styles
hail --preview-style dracula
hail --preview-style ~/styles/mine.json
for s in $(hail --list-styles); do hail --preview-style "$s"; done

hail does not take these two options under the name bash or sh, because bash does not have them.

hail draws the colors of the style in the colors that the terminal has. With COLORTERM=truecolor or COLORTERM=24bit, it draws each color as the style gives it. On a terminal of 256 or 16 colors, such as TERM=xterm-256color or TERM=xterm, it draws the nearest color of the terminal. NO_COLOR and editor.color: false turn the colors off. With TERM=dumb, hail draws no colors and does not edit the line.

hail keeps the background of the terminal. Choose a dark style for a dark terminal, and a light style for a light terminal. The browser build draws its terminal in the background and the foreground of onedark.

The command line

hail takes the command line of bash 5.3. + turns an option off, as in +o errexit or +e. A letter that takes a value takes the next word, so in -oe nounset, -o takes nounset and -e turns on errexit. A lone -o or +o lists the options of set, and a lone -O or +O lists the options of shopt. --pretty-print prints each command of the script as bash prints it, and runs none of them. hail does not support -r, -D and --dump-po-strings yet, and ends with status 2 when one of them is given.

The interactive shell

On a terminal, hail edits each line with rline, and reads the key bindings of the user's inputrc file. It shows PS1 and PS2 with the escapes of bash, such as \w and \[ \], and runs PROMPT_COMMAND and PS0. It colors the line as you type it, and completes the names of commands, files and variables with Tab, and the arguments of a command that complete names. It keeps the history in HISTFILE, with HISTSIZE, HISTFILESIZE, HISTCONTROL, HISTIGNORE and HISTTIMEFORMAT, expands !! and the other history references, and gives the builtins history and fc.

The recordings in docs/demos show the history with Up and Ctrl-R, the editing mode of vi, and job control:

Up brings back the commands before, Ctrl-R finds a command by a part of it, and history lists the commands After set -o vi, Esc and the keys of vi change words of the line Ctrl-Z stops less, sleep runs in the background, jobs lists both, and fg brings less back

bind and set -o vi change the keys at once. bind -x binds a key to a shell command, which reads and changes READLINE_LINE, READLINE_POINT and READLINE_MARK, and reads READLINE_ARGUMENT. Its output goes above the line, as in bash. Esc / completes a file name, Esc ! a command, Esc $ a variable, Esc ~ a user and Esc @ a host, and Ctrl-X with the same key lists the matches. Esc g, Ctrl-X * and Ctrl-X g complete, put in and list what a pattern matches. Esc Ctrl-F, Esc Ctrl-B, Esc Ctrl-D and Esc Ctrl-T move over, kill and swap shell words, where a quoted string is one word. Ctrl-X Ctrl-E edits the line in $VISUAL or $EDITOR and runs it, as in bash, and Ctrl-X Ctrl-V shows the version of bash that hail follows. A key that you bind to dabbrev-expand puts in the newest word of the history that starts with the word at the cursor, and the next press puts in the word before it. A few functions of bash are not in hail yet, such as shell-expand-line and magic-space. bind -l still lists them, and a key that you bind to one does nothing.

On Unix, an interactive hail has job control, as bash has. Ctrl-Z stops the command that runs, and jobs, fg, bg, disown, suspend, wait and kill take job specs such as %1, %+, %-, %sleep and %?text. hail reports a job that ended or stopped before the next prompt, or at once with set -b, also while it waits for you to type. Ctrl-C ends the program that runs, and the rest of the command line. The traps of signals run for a signal that another program sends. At the prompt, a trap of SIGWINCH runs at once, and a trap of a signal such as SIGUSR1 runs before the next command, as in bash. $! is a process ID that another program can see and signal: a job of & has a small copy of hail, a keeper, that stands for it.

Windows

hail runs natively on Windows, built by Go. It finds a program by the extensions of PATHEXT, splits PATH at ";", and reads Path as PATH. A file can run when its extension is in PATHEXT, or when it starts with #!, and test -x decides the same way. A script with a #! line runs through the program that the line names, found in PATH, as Git for Windows does, so #!/usr/bin/env python3 runs python3.exe. hail quotes the arguments of a program as the C runtime of Microsoft reads them, and those of a .bat or .cmd file for cmd.exe, where no argument can run a command or expand a variable. A line break cannot reach a batch file.

hail reads a script whose lines end with CRLF, and $(command) drops the CRs at its end, as bash of Git for Windows does. <(command) and >(command) give the path of a temporary file, because no program of Windows can open /dev/fd/N. /dev/null is the device NUL.

On the console, the interactive shell edits lines with rline. Ctrl-C ends the program that runs. A job of & does not get Ctrl-C, jobs, wait and disown work, and kill ends a job with every process that it started. Windows cannot stop a process, so Ctrl-Z, fg and bg do not work there, and a program sees only the descriptors 0, 1 and 2. A build by TinyGo for Windows compiles and cannot run.

$BASH_VERSION reports the release of bash that hail is compatible with. A script that must behave differently under hail tests $HAIL_VERSION.

Project What hail takes from it
xo/ox Command line parsing, configuration files, help and completion scripts
xo/rline Line editing, history and completion, a pure Go port of isocline
xo/inputrc The reader of inputrc files, which rline uses
xo/transit A pure Go port of tree-sitter, with a bash grammar for highlighting
xo/terminfo The color depth of the terminal
xo/usql The peer whose conventions hail follows, such as config.yaml
reubeno/brush The parser, the interpreter and the tests that hail ports

Documents

Document Holds
docs/DESIGN.md The design, and what three AI models said about it
docs/PLAN.md The direction, and the questions open for the maintainers
docs/PORT.md The pinned releases of brush and bash, and where each part of brush goes
docs/VMS.md The Windows and macOS VMs that test hail, and how to use them
docs/BACKLOG.md The work that is known and not done
docs/decisions/ Each decision, one file each
CONTRIBUTING.md How to change hail and run its tests
AGENTS.md The rules for a coding agent

Contributing

Report a bug, ask a question, or propose a feature in Discussions. See CONTRIBUTING.md.

License

hail is under the MIT license. The YAML test cases that come from brush keep the MIT notice of brush. No file of GNU bash is in this repository.

Documentation

Overview

Command hail is a shell in pure Go that runs bash scripts.

This file follows src/entry.rs and src/args.rs of brush-shell: the command line of bash, read through ox. A hook of each option records it, so that the options of set and shopt apply in the order of the command line, and "+" turns an option off, as in bash (W27). ox reads each word that starts with "+" as options, takes the value of a letter only from the next word, and lets a lone -o, +o, -O or +O end the command line, as bash does (ox's D53).

startup.go reads the startup files by the name of hail and its mode (D19), and package repl runs the interactive shell.

Directories

Path Synopsis
Package arith evaluates the arithmetic of the shell: $((...)), $[...], ((...)), the arithmetic for loop, let, the index of an array, the offset and the length of ${x:offset:length}, and the value of a variable with the integer attribute.
Package arith evaluates the arithmetic of the shell: $((...)), $[...], ((...)), the arithmetic for loop, let, the index of an array, the offset and the length of ${x:offset:length}, and the value of a variable with the integer attribute.
Package console is the terminal of the browser build of hail (D20, W19).
Package console is the terminal of the browser build of hail (D20, W19).
Package env holds the configuration file of hail, config.yaml, and the directory that holds it, as package env does in usql.
Package env holds the configuration file of hail, config.yaml, and the directory that holds it, as package env does in usql.
Package expand expands the words of a command: it turns the text of a word into the fields that the command gets.
Package expand expands the words of a command: it turns the text of a word into the fields that the command gets.
internal
cmd/bench command
Command bench runs a set of scripts under hail, bash and brush, several times each, and prints the time and the memory of each run (W17).
Command bench runs a set of scripts under hail, bash and brush, several times each, and prints the time and the memory of each run (W17).
cmd/bench/helper command
Command helper starts one shell for internal/cmd/bench, and reports what the shell used.
Command helper starts one shell for internal/cmd/bench, and reports what the shell used.
cmd/compat command
Command compat runs the YAML cases of brush under a shell, compares each answer with the golden answer of bash or with the answer that the case gives, and prints how many cases pass, by file (W5).
Command compat runs the YAML cases of brush under a shell, compares each answer with the golden answer of bash or with the answer that the case gives, and prints how many cases pass, by file (W5).
cmd/gnutexts command
Command gnutexts writes the texts of the help of GNU bash 5.3 into two Go files, for the builds of hail with the tag gnubash (D38).
Command gnutexts writes the texts of the help of GNU bash 5.3 into two Go files, for the builds of hail with the tag gnubash (D38).
cmd/golden command
Command golden records the answers of bash to the YAML cases of brush, as golden files (D25).
Command golden records the answers of bash to the YAML cases of brush, as golden files (D25).
cmd/probe command
Command probe checks that the parts hail stands on work when hail is built with TinyGo, as W2 of docs/BACKLOG.md asks.
Command probe checks that the parts hail stands on work when hail is built with TinyGo, as W2 of docs/BACKLOG.md asks.
cmd/wasip2tags command
Command wasip2tags rewrites the build lines of hail so that TinyGo builds hail for WASI preview 2, the target wasip2 (W31).
Command wasip2tags rewrites the build lines of hail so that TinyGo builds hail for WASI preview 2, the target wasip2 (W31).
compat
Package compat reads the YAML cases of brush and the golden files that hold the answers of bash to them (D25).
Package compat reads the YAML cases of brush and the golden files that hold the answers of bash to them (D25).
Package interp is the interpreter of hail: the state of a shell, and the code that runs the tree of package syntax.
Package interp is the interpreter of hail: the state of a shell, and the code that runs the tree of package syntax.
pattern module
Package proc starts a child process for hail.
Package proc starts a child process for hail.
Package repl is the interactive shell of hail: the loop that shows a prompt, reads a command, runs it and shows the next prompt.
Package repl is the interactive shell of hail: the loop that shows a prompt, reads a command, runs it and shows the next prompt.
Package syntax reads the text of a bash script into an abstract syntax tree.
Package syntax reads the text of a bash script into an abstract syntax tree.
Package vfs is the interface through which hail reaches files (D23).
Package vfs is the interface through which hail reaches files (D23).
Command web packs the browser build of a program and its host page into a folder of static files, and serves the folder for a test (D20, D21, W19).
Command web packs the browser build of a program and its host page into a folder of static files, and serves the folder for a test (D20, D21, W19).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL