| .idea | ||
| src | ||
| test | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| README.md | ||
Rush
Rust shell. Inspired by Ion.
In case you're reading this: rush is in the works and not a priority. Features may be missing even if defined below.
Scopes
Variables are block scoped.
Block scope creation:
ifwhileelsefor..$(expr)
Functions have a copy of their scope.
Files create file scopes, to which functions are scoped.
Syntax
; is 'alias' for new line.
Syntax and type errors crash the program.
Variables are scoped to their block, and immediately freed when their block is left.
Variables
String variable value can be obtained using $, arrays using @.
When an array is stringified (referred to with $), it's contents are joined with space.
No special treatment of PATH.
Currently, the shell doesn't error out when variable doesn't exist, instead, it's replaced by an empty string.
Assigned using let.
Left side is evaluated to a string as well.
Variable names must be valid ascii characters, or part of namespace (namespace::var syntax).
let a = d
let $b = c
echo $d # c
Arrays are assigned using [ var ]. You can join arrays and strings by simply passing them there, like [ $var @var ].
Arrays and maps cannot be nested during definition ([ $var [@var] ] should have the same effect).
All assignments are done via the let keyword. If the variable exists, it is overwritten (even in upper scopes).
Instead of =, other operations are supported:
*=- multiply+=- addition-=- substraction/=- division//=- int division%=- modulo::=- append@@=- prepend
Special variables
env:: namespace contains the environment (and doesn't error out if the variable doesn't exist, instead, empty string is returned)
color:: (alias c::) has a number of colors
Return
Sets the exit code (and possibly exits function/script early). If no return is set, the return code is set to the return code of the last expression ($?).
Math
Using $(()) syntax. Math priority applies. Brackets are supported. Variables used without their prepender. Indexing is possible.
String and Array methods
- $trim(str) - Trims the string (both sides)
- $trimLeft(str) - Trims the string (start/left)
- $trimright(str) - Trims the string (end/right)
- $escape(str) - Escapes string
- $unescape(str) - Unescapes string
- @split(str by) - Splits
strbybyinto array - @join(str by=" ") - Joins
strtogetherby
Slices: [x..y] gets a substring (or subarray) of the variable. When x ommited, defaults to 0 (the start). When y ommited, defaults to end.
Control
Bracketless. Scopes are ended by the keyword end.
if- Runs it's scope if the command returns0. Useful in pair withtestbuiltin.elsesupported.else ifdoesn't require anotherend.for val of @arr- Runs for each value of the array (or hashmap)for val of X..Y- Runs for each number in the rangeXandY(both inclusive).while- Runs in loop as long as the command returns0
Functions
Defined by fn name [...arg] [--flags]. arg can be ommited, or repeated.
--flags can be used to add additional functionality.
Functions are scoped per file, even if they use on-event or similar to be triggered.
Use source to load external files with functions to be triggered.
--descsets the functions description.--on-eventwill run the function when an event is run
Builtins
let is a special case which cannot be dynamically addressed (i.e. using $(echo let) var = value).
letfor assigning variables (let var = value)exportfor exporting variables to env (export varto export var, orexport var = value)testtests for evaluation (=for equality,>,<,<=,>=for number comparisons)existsfor existence of a given string, or if given a flag (-Functions,-variables,-env,-file,-directory,-readable file,-writable file, e-xecutable file), existence of the selected objecttruereturns0falsereturns1sourceto run another file in the same file scopetypeofreturns the type of arguments passedinspectshows the object in a debug output
Some GNU standard utils may be overwritten by rush builtins, but must be made compatible.