ela
Contents

ManualLanguage

Variables

In the terminalela --spec variables

  • Assignment allows spaces around =: name = "amber".
  • Variables are read with $: $name.
  • No word splitting: $file is always passed as exactly one argument, so quoting variables is never needed.
  • Multiple values use a real list type.
  • Reading an undefined variable is an error, never a silent empty string.
  • Script arguments are in the built-in list args: $args[0], len($args). No $1, $2. args is built in, as env is: no variable, constant, parameter, loop variable, proc or import can take the name, in a proc's body either, and a script that tries, args = [] anywhere, a branch that never runs included, stops before line 1.
  • done is no variable's name (Statements and blocks): finished = true.
  • _ takes a value and drops it: out, _ = try $(git describe). It holds nothing, so $_ is an error.

The environment #

The environment is reached through env, never by a bare name, so $name is always an ela variable and the two never hide each other. env is built in, as args is: no variable, constant, parameter, proc or import can take the name, and a script that tries, env = "staging" anywhere, a branch that never runs included, stops before line 1. $env.NAME and env.NAME = value are part of the language, and env.get, env.has, env.remove and env.from_bash are its procs.

  • $env.HOME reads an environment variable, in code, in a command and in a double-quoted string alike: cp app.toml $env.HOME/.config/app/. One that is not set is an error that names env.get. $keyring.NAME reads a secret from the keyring the same way (PACKAGES.md, Keyring).
  • env.NAME = value sets one for every later command and for the rest of the script: env.PATH = "$env.PATH:/opt/odin".
  • env.NAME = null removes one for every later command and for the rest of the script, as env.remove("NAME") does; removing one that is not set is fine. After it $env.NAME is the not-set error, env.has is false and no command the script runs gets it. "null" in quotes is text: env.MODE = "null" sets the four letters.
  • with env.NAME = value sets one for a block only, and with env.NAME = null removes one for a block only; at end with it has its old value again, or stays removed if it was not set (with).
  • The environment is the script's own: a copy of the one ela started with, which env.NAME = value, env.remove, with env. and cd (its PWD and OLDPWD) change, and which every command the script runs is given, as are its imported files. ela's own process environment stays as it started, so what ela itself reads from it, such as the local time zone's TZ, is what it started with.
Built-inDoes
env.get(name, fallback = "")The variable's value, or fallback when it is not set or empty; always text, so a number or a boolean fallback is given as its text, as env.NAME = value stores it
env.has(name)Whether the variable is set
env.remove(name)Removes the variable, as env.NAME = null does; one that is not set is fine
env.from_bash(line)Runs a line of bash and takes the variables it set, changed or unset into the environment

env.from_bash(line) takes a line of bash that an install guide puts in .profile, as it is written, in '...' so that $HOME and $( ) are left for bash: . "$HOME/.cargo/env", eval "$(brew shellenv)". bash runs it, starting from ela's environment, and the variables it added, changed or unset are added, changed or removed in ela's, a value with a line break among them. Only variables cross: a function, an alias or a prompt hook stays in that bash (nvm, mise activate). What the line prints reaches the terminal. A line that fails, a file missing among them, is an error with the exit code and bash's own message, and changes nothing; with no bash on PATH it is an error too. It runs a program, so an imported file's constant can't call it. Its place is login.ela (SHELL.md, Login shell).

env.from_bash('. "$HOME/.cargo/env"')env.from_bash('eval "$(ssh-agent -s)"')
makehub = env.get("CI_STATUS_MAKEHUB", "https://makehub.example")if env.has("CI")    echo "running in CI"end if with env.KUBECONFIG = null    kubectl --server https://cluster.example get podsend with

Constants #

NAME :: value at the top level binds a name once, to any expression, worked out when its line runs. It is read as $NAME everywhere, in procs too, and never assigned again. Its name is UPPER_CASE (Naming style).

ENDED :: ["passed", "failed", "stopped"]CONFIG :: "$env.HOME/.config/deploy" proc ended(state: string)    return has($ENDED, $state)end proc
  • A constant is declared only at the top level of a script, of init.ela or of an imported file, once.
  • Assigning a constant, or a proc's parameter or variable named like one, is an error.
  • A proc that reads a constant whose line has not run yet is an error that names the line.