mirror of
https://github.com/danbulant/rush
synced 2026-05-19 04:18:35 +00:00
add nix & update readme
This commit is contained in:
parent
3064ba5b17
commit
a28299cfcd
3 changed files with 41 additions and 120 deletions
9
.envrc
Normal file
9
.envrc
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
# the shebang is ignored, but nice for editors
|
||||
|
||||
if type -P lorri &>/dev/null; then
|
||||
eval "$(lorri direnv)"
|
||||
else
|
||||
echo 'while direnv evaluated .envrc, could not find the command "lorri" [https://github.com/nix-community/lorri]'
|
||||
use nix
|
||||
fi
|
||||
120
README.md
120
README.md
|
|
@ -1,123 +1,3 @@
|
|||
# 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:
|
||||
- `if`
|
||||
- `while`
|
||||
- `else`
|
||||
- `for..`
|
||||
- `$(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).
|
||||
|
||||
```sh
|
||||
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 `str` by `by` into array
|
||||
* @join(str by=" ") - Joins `str` together `by`
|
||||
|
||||
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 returns `0`. Useful in pair with `test` builtin. `else` supported. `else if` doesn't require another `end`.
|
||||
- `for val of @arr` - Runs for each value of the array (or hashmap)
|
||||
- `for val of X..Y` - Runs for each number in the range `X` and `Y` (both inclusive).
|
||||
- `while` - Runs in loop as long as the command returns `0`
|
||||
|
||||
### 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.
|
||||
|
||||
- `--desc` sets the functions description.
|
||||
- `--on-event` will 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`).
|
||||
|
||||
* `let` for assigning variables (`let var = value`)
|
||||
* `export` for exporting variables to env (`export var` to export var, or `export var = value`)
|
||||
* `test` tests for evaluation (`=` for equality, `>`, `<`, `<=`, `>=` for number comparisons)
|
||||
* `exists` for existence of a given string, or if given a flag (`-F`unctions, `-v`ariables, `-e`nv, `-f`ile, `-d`irectory, `-r`eadable file, `-w`ritable file, e`-x`ecutable file), existence of the selected object
|
||||
* `true` returns `0`
|
||||
* `false` returns `1`
|
||||
* `source` to run another file in the same file scope
|
||||
* `typeof` returns the type of arguments passed
|
||||
* `inspect` shows the object in a debug output
|
||||
|
||||
Some GNU standard utils may be overwritten by rush builtins, but must be made compatible.
|
||||
|
|
|
|||
32
shell.nix
Normal file
32
shell.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
let
|
||||
unstable = import (fetchTarball "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz") { };
|
||||
# rust-rover things
|
||||
rust-toolchain =
|
||||
pkgs.symlinkJoin {
|
||||
name = "rust-toolchain";
|
||||
paths = with unstable; [rustc cargo rustPlatform.rustcSrc clippy rustfmt gcc rust-analyzer];
|
||||
};
|
||||
in
|
||||
pkgs.mkShell rec {
|
||||
buildInputs = with unstable;[
|
||||
openssl
|
||||
pkg-config
|
||||
cmake
|
||||
zlib
|
||||
rust-toolchain
|
||||
|
||||
cargo-flamegraph
|
||||
hyperfine
|
||||
valgrind
|
||||
|
||||
lld
|
||||
];
|
||||
nativeBuildInputs = with unstable; [
|
||||
pkg-config
|
||||
];
|
||||
LD_LIBRARY_PATH = "${unstable.lib.makeLibraryPath buildInputs}";
|
||||
OPENSSL_DIR="${unstable.openssl.dev}";
|
||||
OPENSSL_LIB_DIR="${unstable.openssl.out}/lib";
|
||||
RUST_SRC_PATH = "${unstable.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||
}
|
||||
Loading…
Reference in a new issue