hail

command module
v0.0.0-...-79e800d Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 25 Imported by: ? 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

hail

hail is a bash shell written in pure Go. It runs your bash scripts, and you can use it as your shell at the terminal. It is one static binary with no C library, for Linux, macOS, Windows, FreeBSD and NetBSD, and it also runs as WebAssembly.

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


Unit Tests Go Reference Releases Discord Discussion

What hail gives you

  • hail gives the output, the errors and the exit status of GNU bash 5.3. On the tests of GNU bash 5.3, hail gives the answers of bash on 84 of 86 test files, and brush 0.5.0 on 12. On the 3,740 cases of brush that test what bash does, checked against the answers of bash, hail passes 3,730 and brush 2,862.
  • hail uses no cgo and links no C library. It runs natively on Windows, without MSYS or Cygwin, and it builds with TinyGo and for WebAssembly.
  • The interactive shell has line editing in emacs or vi mode, your inputrc, history, Tab completion that works with bash-completion, colors as you type in any of 168 styles, and job control.
  • A script behaves the same on every machine, because hail reads no bashrc. Your settings go in config.yaml, which only the interactive shell reads.

hail started as a port of brush, a bash written in Rust, and follows bash where the two differ. It is also the full example of three xo packages: ox for the command line, rline for line editing, and transit for syntax highlighting.

Installing

Build hail from source with Go, with cgo turned off, so that the binary is static:

git clone https://github.com/xo/hail.git
cd hail
CGO_ENABLED=0 go build .

On Linux, you can also build hail with TinyGo. Give TinyGo the flag -stack-size=8MB, which hail needs for a deep recursion (D28):

tinygo build -stack-size=8MB .

Each release on the Releases page will hold builds for Linux, macOS and Windows on amd64 and arm64, for FreeBSD and NetBSD on amd64, and the builds of TinyGo for WASI and for the browser. There is no release yet.

The texts of help in GNU bash are under the GPL, so hail gives a short text of its own for each builtin. CONTRIBUTING.md says how to make a build with the texts of bash (D38).

Using hail

hail takes the command line of bash 5.3:

hail                         # an interactive shell
hail script.sh arg1 arg2     # run a script
hail -c 'echo "$1"' hail hi  # run a command
hail -n script.sh            # check a script without running it
hail --pretty-print x.sh     # print a script as bash prints it

hail --help lists the options. hail does not support -D and --dump-po-strings yet, and ends with status 2 when it gets one of them.

To run a script with hail, put hail in its first line, or run it with hail script.sh:

#!/usr/bin/env hail

$BASH_VERSION reports the release of bash that hail follows. A script that must know that hail runs it tests $HAIL_VERSION.

Using hail as bash

Started under the name bash, hail acts as bash. It reads the startup files of bash in place of config.yaml: /etc/profile and the first of ~/.bash_profile, ~/.bash_login and ~/.profile for a login shell, and ~/.bashrc for an interactive shell that is not a login shell. A login shell runs ~/.bash_logout when it ends. hail does not read /etc/bash.bashrc, which some systems build into their bash. To try it from bash:

exec -a bash hail

A link named bash to hail does the same. Do not put such a link before the real bash in PATH, because every script that runs bash then runs hail.

Under the name sh, hail turns on POSIX mode, reads /etc/profile and ~/.profile for a login shell, and reads the file that $ENV names for an interactive shell. Under the name rbash, or with -r, hail is a restricted shell, as bash is. A restricted shell is not a sandbox (D39).

Under its own name, hail reads no bash startup file. To try your bash setup in hail, source it at the prompt:

source ~/.bashrc

Configuration

An interactive hail reads config.yaml from its configuration directory. A script that hail runs does not read it:

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. 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'
source:                   # scripts to run, relative to the directory of the file
  - functions.sh

Put functions in a bash script, and name the script under source. --norc turns the file off.

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

hail reads your inputrc file first, and then the lines of editor.bindings, as one more inputrc file. So a binding in config.yaml replaces a binding of the same keys in your inputrc. Each line is a line that you can give to bind. Write each line in single quotes, so that YAML keeps each backslash.

Styles

hail colors the line as you type it, with a style of transit. It bundles the 168 styles of transit, and the default style is onedark.

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

hail --list-styles
hail --preview-style dracula

To choose a style, name it under editor.style. editor.style also takes the path of a JSON style file in the form of transit, relative to the directory of config.yaml. editor.styles changes the style of one kind of word: comment, constant, embedded, function, keyword, number, operator, property or string. An empty value takes the color off. Put a value that holds # in quotes, because YAML starts a comment at #:

editor:
  style: dracula
  styles:
    comment: 'italic #6272a4'
    keyword: bold ansi-fuchsia
    string: ''

hail draws each color as the style gives it when COLORTERM is truecolor or 24bit, and the nearest color on a terminal of 256 or 16 colors. It keeps the background of the terminal, so choose a dark style for a dark terminal. NO_COLOR and editor.color: false turn the colors off.

The interactive shell

On a terminal, hail edits each line with rline, and reads the key bindings of your inputrc file. It shows PS1 and PS2 with the escapes of bash, and runs PROMPT_COMMAND and PS0. Tab completes commands, files and variables, and the arguments of a command that complete names, so the functions of bash-completion work. The history follows HISTFILE, HISTSIZE, HISTCONTROL, HISTIGNORE and HISTTIMEFORMAT, and !! and the other history references expand.

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

The keys of bash work, among them:

Keys What they do
Up, Down, Ctrl-R Go through the history, and search it
Tab Complete the word at the cursor
Esc /, Esc !, Esc $, Esc ~, Esc @ Complete a file, a command, a variable, a user or a host
Ctrl-X Ctrl-E Edit the line in $VISUAL or $EDITOR, and run it
Esc Ctrl-F, Esc Ctrl-B Move over a shell word, where a quoted string is one word

bind and set -o vi change the keys at once, and bind -x binds a key to a shell command that can read and change READLINE_LINE. A few functions of bash are not in hail yet, such as shell-expand-line and magic-space.

On Unix, hail has job control, as bash has. Ctrl-Z stops the command that runs, and jobs, fg, bg, disown, wait and kill take job specs such as %1 and %+. hail reports a job that ended or stopped before the next prompt.

Windows

hail runs natively on Windows. It finds a program by the extensions of PATHEXT, and runs a script with a #! line through the program that the line names, as Git for Windows does, so #!/usr/bin/env python3 runs python3.exe. It reads scripts with CRLF line ends. It shows paths as Git Bash does, as in /c/Users.

<(command) and >(command) give the path of a temporary file, because no program of Windows can open /dev/fd/N. Windows cannot stop a process, so Ctrl-Z, fg and bg do not work there. A build of TinyGo for Windows is not supported.

Project What hail takes from it
xo/ox Command line parsing, configuration files, help and completion scripts
xo/rline Line editing, history and completion
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

Contributing

Report a bug, ask a question, or propose a feature in Discussions. CONTRIBUTING.md says how to build hail and run its tests. The design is in docs/DESIGN.md, where hail stands is in docs/PLAN.md, the known work is in docs/BACKLOG.md, and each decision is in docs/decisions.

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
⌂ 换网址