Skip to content
Snippets Groups Projects
Forked from redox-os / ion
1687 commits behind the upstream repository.
README.md 9.88 KiB

Ion Shell

Build Status MIT licensed Coverage Status crates.io

Ion is a shell for UNIX platforms, and is the default shell in Redox. It is still a work in progress, but much of the core functionality is complete. Features below:

  • Shell Expansion
  • Flow Control
  • Aliases
  • Variables ($variable)
  • Functions
  • Arrays (@array)
  • Array Expressions ([])
  • Array-based Command Substitution (@[])
  • String-based Command Substitution ($())
  • Array Methods (@split(var, ' '))
  • String Methods ($join(array, ', '))
  • Array Splicing
  • Maps
  • For Loops
  • Foreach Loops
  • While Loops
  • If Conditionals
  • Piping Stdout/Stderr
  • Redirecting Stdout/Stderr
  • Piping Builtins & Functions
  • && and || Conditionals
  • Background Jobs
  • Background Jobs Control
  • Signal Handling
  • Autosuggestions (90%)
  • Syntax Highlighting
  • Multiline Comments and Commands
  • Multiline Editing
  • Tab Completion (Needs Improvements)
  • Syntax for Color Handling
  • Unescape specific character combinations, such as '\n' and '\t'
  • Builtin Plugins
  • Prompt Plugins

Shell Syntax

Defining Variables

The let keyword is utilized to create local variables within the shell. The export keyword performs a similar action, only setting the variable globally as an environment variable for the operating system.

let git_branch = $(git rev-parse --abbrev-ref HEAD ^> /dev/null)

If the command is executed without any arguments, it will simply list all available variables.

Using Variables

Variables may be called with the $ sigil, where the value that follows may be a local or global value. They may also be optionally defined using a braced syntax, which is useful in the event that you need the value integrated alongside other characters that do not terminate the variable parsing.

let a = one
let b = two
echo $A:$B
echo ${A}s and ${B}s

Dropping Variables

To drop a value from the shell, the drop keyword may be used:

drop git_branch

Variable Arithmetic

The let command also supports basic arithmetic.

let a = 1
echo $a
let a += 4
echo $a
let a *= 10
echo $a
let a /= 2
echo $a
let a -= 5
echo $a

Export

The export command works similarly to the let command, but instead of defining a local variable, it defines a global variable that other processes can access.

export PATH = "~/.cargo/bin:${PATH}"

Export Arithmetic

The export command also supports basic arithmetic.

export a = 1
echo $a
export a += 4
echo $a
export a *= 10
echo $a
export a /= 2
echo $a
export a -= 5
echo $a

Aliases

The alias command is used to set an alias for running other commands under a different name. The most common usages of the alias keyword are to shorten the keystrokes required to run a command and it's specific arguments, and to rename a command to something more familiar.

alias ls = 'exa'

If the command is executed without any arguments, it will simply list all available aliases.

The unalias command performs the reverse of alias in that it drops the value from existence.

unalias ls