rsh 0.72
rsh, or Rsh for short, is a new shell that takes a modern, structured approach to your command line. It works seamlessly with the data from your filesystem, operating system, and a growing number of file formats to make it easy to build powerful command line pipelines.
Today, we're releasing version 0.72 of Rsh. This release includes many new features: mutability, looping, early returns, changes to the core commands, and much more.
Where to get it
Rsh 0.72 is available as
pre-built binaries
or from
crates.io. If you have Rust installed you can install it using
cargo install rsh.
NOTE: as part of this release, we are no longer including
additional features in --features=extra. With 0.72,
SQLite features have moved into the main rsh installation and
dataframe functionality is now part of
--features=dataframe.
As part of this release, we also publish a set of optional
plugins you can install and use with Rsh. To install, use
cargo install rsh_plugin_<plugin name>.
Themes of this release / New features
Try/catch
Starting with 0.72, it's now much easier to run a command that might fail and then handle the failure if it happens.
try {
1 / 0
} catch {
print "look, no crash"
}
The catch part of the try/catch is
optional. Without it, the try block will run, and
any error that occurs will be ignored.
You can also access the error, if one happens, using a closure syntax:
try {
1 / 0
} catch {|e|
print "look, no crash."
print $e
}
Auto-expanding data views
With the new default config, we now also detect the terminal width and will automatically expand the data view to include more information if it's available.
This uses an improved expanding data view capability from 0.70.
Redirection
This release also includes a new way of redirecting the stdout and/or stderr of external commands. This gives easier access to the output streams than was previously possible.
> cat foo.txt out> bar.txt
> cat missingfilename.txt err> my_error.txt
You can also create a stream built from the above, allowing one stream to empty and then be followed by the other stream:
> git status out+err> git_status.txt
Closures/blocks
We have now split closures and blocks into two separate value types. A closure can have parameters, can close over variables outside of its scope, and can be passed as a value.
An example closure:
ls | each {|it| print $it.name }
You can also think of creating a custom command like
def foo [] { ... } as creating a closure.
A block is much simpler and is used as the bottom of commands
like if and loops.
An example block:
if true {
print "hello!"
}
Blocks don't close over (or capture) variables, don't have parameters, and can't be passed as a value. Blocks, however, do have one special trick...
Mutation
Starting in this release, you can create local mutable
variables. You can create mutable variables using the
mut keyword:
mut x = 1
$x = $x + 100
print $x
A mutable variable can only live and change in the closure in
which it's created. Blocks, however, have access to the
mutable variables in the parent closure. For example, mutating a
variable inside of the block used in an if call is
valid:
mut x = 1
if true {
$x += 1000
}
print $x
Loop/while
The 0.72 release also includes a few new looping commands:
loop and while.
The loop command runs a block forever:
loop {
print "hit ctrl-c to break out of this example"
}
The while command will run its block as long as a
condition is met:
mut x = 0
while $x < 10 {
print $x
$x += 1
}
Break/continue
Loops can now also use the break and
continue feature common in many programming
languages. break will break out of the current
loop. And continue will continue the loop at the
next iteration.
Return
The 0.72 release also includes the ability to return early from a closure or command.
def foo [x] {
if $x > 10 {
return 1000
}
0
}
Command refinement, simplification, and elimination
This release contains many breaking changes to Rsh's built-in commands (sorry!). As we move toward version 1.0 we want to ensure that Rsh ships with a small curated set of consistent, well-designed "standard library" commands. This requires taking a hard look at existing commands, and in some cases breaking changes are unavoidable. We expect that this effort will span a few release cycles.
Dataframes no longer included by default - smaller binaries
Rsh's dataframe support is extensive, impressive, and very useful to users who rely on it. However, it comes at a high cost in terms of compile time, binary size, and complexity. Starting with version 0.72, dataframe commands are no longer included in the release binaries published on GitHub or the default binaries published via package managers (like Homebrew, winget, Scoop). As a result of this change, the main Rsh executable is now about 50% smaller.
To continue using dataframe commands, you can build Rsh from
source using the dataframe
Cargo feature. For example, to install using Cargo:
cargo install rsh --features=dataframe
Allow reloading overlay definitions (kubouch)
A common pattern in using overlays is shadowing an existing
environment variable, such as PROMPT_COMMAND. However,
overlay use would keep loading the value from the
first activation. It is best explained with an example. Assume
the following module:
module prompt {
export-env {
let-env PROMPT_COMMAND = (date now | into string)
}
}
Calling overlay use prompt for the first time
changes the prompt to the current time, however, subsequent
calls to overlay use won't change the time.
That's because overlays, once activated, store their state
so they can be hidden and restored at later time. To
force-reload the environment, we added a new
--reload flag: Calling
overlay use --reload prompt repeatedly now updates
the prompt with the current time each time.
virtualenv activation changes (kubouch)
Since the version 20.17.0 of
virtualenv, the new way to activate an environment is to call
overlay use activate.rsh instead of the
source activate.rsh. This change is in line with
gradual deprecation of source and moving us towards
using modules as overlays in more cases. Please, check the
activation script itself
for more details.
Breaking changes
- As mentioned above, dataframe support has been removed from the default Rsh binaries.
-
Rsh's SQLite DSL commands have been removed.
open foo.dbandopen foo.db | query db "SELECT * ..."still work, but the commands which mapped 1-to-1 with SQL clauses (ex:open foo.db | into db | select * | from table some_table | order-by some_column) have been removed. These commands were an interesting experiment but they didn't work out, and we're removing them to simplify database access in Rsh. -
The
is_plugin,is_custom, andis_keywordcolumns inhelp commandshave been replaced with a singlecommand_typecolumn. -
date formatnow returns an error if not given an input. Previously it would default to the current time. -
firstandlastwill now return an error if given a negative index. Previously the behavior was undefined and may have returned entries due to an underflow. -
The
--predicateflag has been removed fromfind.wherecan be used in all situations wherefind --predicatewas previously used. -
sort-bynow requires a column name to sort by. To sort lists without specifying a column name,sortcan be used. -
seq,seq char, andseq dateno longer have--separatorand--terminatorflags (#7045, #7054, #7096). This helps ensure that the return type for those commands is consistent, andstr joincan be used to accomplish the same effect. -
The
build-stringcommand has been removed. To concatenate strings, use the+operator, string interpolation, orstr join. -
wrapnow expands ranges. It works the same as with lists orseq. -
url parseurl scheme,url host,url path, andurl querycommands have been removed. We added the commandurl parse. This new command returns a Record with scheme, username, password, host, path, query, params (as a Record) and fragment. -
sort,sort-by,str containsandfindhave had their--insensitiveflags renamed to--ignore-case..--ignore-caseis used byuniq, as well as popular external commands likeless,grepandwget, so it could be considered a standard flag name.
New boolean operator xor - Planned operator
simplification
To complement our logical boolean operators
and/&& and
or/|| we
added boolean xor. This is consistent with bit-and,
bit-xor, and bit-or.
We are currently considering to deprecate the C-style symbols
&&/|| in favor of the spelled
out and/or to increase consistency and
provide more actionable error messages when trying to use
&&/|| in a similar fashion to
bash.
Config options have been grouped together
The structure of $env.config (and thus the record used with
let-env config = statements in
config.rsh and other places) has been reorganised.
Various options are now grouped into subrecords (similar to
table_trim) and had their names shortened. This
allows config.rsh files to be better structured,
and thus easier to edit and read, while also allowing future
options to be added without making the
WARNING
Your existing config.rsh options WILL still work
in this version!! However, you will get a warning message if
you use the old versions of the options (as you might already
be aware). Support for these old options will be dropped in a
future rsh update, so take care to convert your
config.rsh files when you can.
The changes are:
-
use_ls_colorsandclickable_linkshave been moved to into anlssubrecord. -
rm_always_trashhas been moved into thermrecord. Furtherrmconfig options to accompany it may appear in the future. -
cd_with_abbreviationshas been moved into acdrecord. Furthercdconfig options to accompany it may appear in the future. -
history_file_format,sync_history_on_enterandmax_history_sizehave been moved to ahistorysubrecord. -
filesize_metricandfilesize_formathave been moved to afilesizesubrecord. -
case_sensitive_completions,quick_completions,partial_completionsandcompletion_algorithmhave been moved into acompletionssubrecord. -
The
completionssubrecord also contains anexternalsubrecord.-
enable_external_completion,max_external_completion_results, andexternal_completerhave been moved into the aforementioned subrecord.
-
-
table_mode,table_index_modeand thetable_trimsubrecord have been moved into atablesubrecord.
The new grouped options look like this:
ls: {
use_ls_colors: true # use the LS_COLORS environment variable to colorize output
clickable_links: true # enable or disable clickable links. Your terminal has to support links.
}
rm: {
always_trash: true # always act as if -t was given. Can be overridden with -p
}
cd: {
abbreviations: true # allows `cd s/o/f` to expand to `cd some/other/folder`
}
table: {
mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
index_mode: always # "always" show indexes, "never" show indexes, "auto" = show indexes when a table has "index" column
trim: {
methodology: wrapping # wrapping or truncating
wrapping_try_keep_words: true # A strategy used by the 'wrapping' methodology
truncating_suffix: "..." # A suffix used by the 'truncating' methodology
}
}
history: {
max_size: 10000 # Session has to be reloaded for this to take effect
sync_on_enter: true # Enable to share history between multiple sessions, else you have to close the session to write history to file
file_format: "plaintext" # "sqlite" or "plaintext"
}
completions: {
case_sensitive: false # set to true to enable case-sensitive completions
quick: true # set this to false to prevent auto-selecting completions when only one remains
partial: true # set this to false to prevent partial filling of the prompt
algorithm: "prefix" # prefix or fuzzy
external: {
enable: true # set to false to prevent rsh looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up my be very slow
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options
completer: null # check 'carapace_completer' above as an example
}
}
filesize: {
metric: true # true => KB, MB, GB (ISO standard), false => KiB, MiB, GiB (Windows standard)
format: "auto" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto
}
To output your existing options in the above format (that could be pasted into your config.rsh file before you delete the old options), run this code in your copy of rsh:
$env.config | do { { ls: { use_ls_colors: $in.use_ls_colors clickable_links: $in.show_clickable_links_in_ls } rm: { always_trash: $in.rm_always_trash } cd: { abbreviations: $in.cd_with_abbreviations } table: { mode: $in.table_mode index_mode: $in.table_index_mode trim: $in.table_trim } history: { max_size: $in.max_history_size sync_on_enter: $in.sync_history_on_enter file_format: $in.history_file_format } completions: { case_sensitive: $in.case_sensitive_completions quick: $in.quick_completions partial: $in.partial_completions algorithm:$in.completion_algorithm external: { enable: $in.enable_external_completion max_results: $in.max_external_completion_results completer:$in.external_completer } } } } | to nuon | str substring 1..-1
Minimum Rust version has bumped to 1.65
Due to some breakage in dependencies, we've gone ahead and bumped the required version of Rust to 1.65, which addresses the issue. Apologies to anyone who is inconvenienced by the bump. We anticipate returning to the Rust-1 versions in the future.
Full changelog
rsh
-
fdncred created
update release-pkg.rsh to include more recent less
version, and
add a more verbose description of operators, and
add
help operatorscommand, and pin to rust v1.65, and pin to a version of zstd that doesn't break dataframe compilation, and addinto recordcommand, and update default_config.rsh with display_output, and fixansi --oscparameter adding extra semi-colon, and reset stack size to 10mb vs 2gb, and fix plugin detection in help commands, and add commented out mold linker usage, and use path.try_exist() to fix silent errors, and bump to dev release 0.71.1, and return value::int instead of value::record inhistory session -
rgwood created
Clean up .sh scripts with shellcheck, and
Make catch block a closure w/ access to error, and
Feature cleanup, and
Remove
build-stringcommand, and Return errors on unexpected inputs totakeandfirst, and Improvermerror message when file not found, and Remove --separator fromseq date, and Fix CI failures after PR merge conflicts, and Simplifyseq char, and Make seq output type consistent (by removing flags) -
sholderbach created
Add did-you-mean suggestions for operators, and
Add logical
xoroperator, and Removesamples/wasmfolder, and Error on negative argument offirst, and Error on negative argument tolast, and Try --locked install in virtualenv CI tests, and Remove accidentalstrip-ansi-escapesafter #6938 -
jt created
Clean up keyword lines in help, and
New commands:
break,continue,return, andloop, and Remove And and Or pipeline elements, and Add try/catch functionality, and A set of fixes for stderr redirect, and Don't redirect stdout when only redirecting stderr, and Stdout/Stderr redirection, and Move dataframe out of extra, and Add auto-expanding table view to default config, and Parser refactoring for improving pipelines, and Add additional assignment operators, and Add support for while loops, and Allow field assignment into the env variable, and Update README re: typechecking, and Fix environment conversions, and Limited mutable variables, and Convert 'for' to a statement, and Split blocks and closures, and Turn off foreground processes on macOS - stormasm created Revert "remove zstd warning message", and remove zstd warning message
- kubouch created Reorder export-env eval and allow reloading an overlay, and Update PR template and contributing guide, and Change parser cwd when running a file
- dmatos2012 created fix color_config crashing on nonstring data, and fix overflow on negative bytes
-
webbedspace created
Fix
fetch/postnot erroring on 4xx and 5xx statuses, and Fixsort-by,path joinandsizeerror arrows, and Change all--insensitiveflags to--ignore-case, and Fixmverror message issues (arrows, Windows paths), and Fixgloberror arrows, and Remove erroneous test introduced in #6994, and Rename dataframedescribetosummaryso that the normaldescribeisn't overloaded, and Bugfix: add table_index_mode check that was missing from #6983, and Editrmhelp messages, and Improve CantFindColumn and ColumnAlreadyExists errors, and Improverun-external's "Cannot convert argument to string" message, andto html --listnow returns a table, and Replace all instances of 'column path' inhelpmessages with 'cell path', and Addhelpwarnings forpath existsandpath typeregarding usage, and Fix needs_quotes() into nuon(closes #6989) - michel-slm created Add binstall metadata
-
raccmonteiro created
uniq -idoes not convert to lowercase (#7192), anduniqcode refactoring, and avoid test failure caused by locale thousand separator, and new commandurl parse(#6854) andurlsubcommands tests, and commandopenreturns error when does not have parameters (#7048), and Type validation forheaderscommand (#6918) -
kamirr created
Fix while ctrlc behavior, and
Fix
lastmemory use - nibon7 created Apply clippy fix
- dependabot[bot] created Bump minimatch from 3.0.4 to 3.1.2 in /samples/wasm
- WindSoilder created remove block input support in merge, and Plugin: make friendly error message when python is not found, and Make external command substitution works friendly(like fish shell, trailing ending newlines), and add signature information when get help on one command
-
nanoqsh created
Fixed json parsing, and
Consistent
wrap - zhiburt created fix #7145
- Decodetalkers created fix: ls not show pattern error, and chore: chrono_update, and feat: Use Raw text to save if pipeline data is ExternalStream or String
- SUPERCILEX created Restore original do -i behavior and add flags to break down shell vs program errors
-
dandavison created
Add missing strip-ansi-escapes dependency to
Cargo.lock, and
Add input-output types to $rsh.scope.commands, and
Refactor create_scope, and
Fix command_type classification, and
Collapse some
help commandscolumns into a single column - denstiny created fix(#7097): let-env should not be able to set PWD
Extension
- fdncred created updates for rsh 0.72
Documentation
-
sholderbach created
Fix tip boxes in
book/custom_commands.md, and Fix octal literal mentions, and Update operator docs -
WindSoilder created
remove
Subexpressions with external commandssession - dmatos2012 created expand docs on using use with export-env
-
webbedspace created
Release Notes: add note about
--ignore-case, and Add config.rsh structure changes -
raccmonteiro created
document
url parsecommand - casidiablo created Fix typo in advanced.md page
- remlse created Fix variable path expression example
- nanoqsh created Document wrap update
- hustcer created Refresh commands docs for rsh v0.71
- hbt created fix 404 link
- jt created Create a section for the 0.80 philosophy
rsh_Scripts
- WindSoilder created fix merge doesnt support block input
- Joxtacy created Add zellij completions
- Emilgardis created improve cargo completions
- tshaynik created Add custom completions for nix
- fdncred created updates get-weather to remove the for loop
- taooceros created Fix undetected windows environment
reedline
- rgwood created Fix example in CONTRIBUTING.md