nushell/README.md

174 lines
9.1 KiB
Markdown
Raw Normal View History

2019-07-17 20:13:09 +00:00
[![Build Status](https://dev.azure.com/nushell/nushell/_apis/build/status/nushell.nushell?branchName=master)](https://dev.azure.com/nushell/nushell/_build/latest?definitionId=2&branchName=master) [![Discord](https://img.shields.io/discord/601130461678272522.svg?logo=discord)](https://discord.gg/NtAbbGn)
2019-05-17 16:59:25 +00:00
# Nu Shell
2019-06-15 18:50:50 +00:00
Like having a shell in a playground.
2019-05-17 16:59:25 +00:00
# Status
2019-06-15 02:24:13 +00:00
This project is currently in its early stages, though it already works well enough for contributors to dogfood it as their daily driver. Its design is subject to change as it matures.
2019-05-17 16:59:25 +00:00
2019-06-15 04:20:58 +00:00
Nu has a list of built-in commands (listed below). If a command is unknown, the command will shell-out and execute it (using cmd on Windows or bash on Linux and MacOS), correctly passing through stdin, stdout and stderr, so things like your daily git workflows and even `vim` will work just fine.
2019-05-17 16:59:25 +00:00
2019-06-15 02:24:13 +00:00
# Philosophy
2019-07-12 20:00:49 +00:00
Nu draws inspiration from projects like PowerShell, functional programming languages, and modern cli tools. Rather than thinking of files and services as raw streams of text, Nu looks at each input as something with structure. For example, when you list the contents of a directory, what you get back in a list of objects, where each object represents an item in that directory. These values can be piped through a series of steps, in a series of commands called a 'pipeline'.
2019-06-15 02:24:13 +00:00
## Pipelines
2019-07-12 17:39:55 +00:00
In Unix, it's common to pipe between commands to split up a sophisticated command over multiple steps. Nu takes this a step further and builds heavily on the idea of _pipelines_. Just as the Unix philosophy, Nu allows commands to output from stdout and read from stdin. Additionally, commands can output structured data (you can think of this as a third kind of stream). Commands that work in the pipeline fit into one of three categories
2019-06-15 02:24:13 +00:00
2019-06-15 04:20:58 +00:00
* Commands that produce a stream (eg, `ls`)
2019-07-16 19:10:25 +00:00
* Commands that filter a stream (eg, `where type == "Directory"`)
2019-06-15 04:20:58 +00:00
* Commands that consumes the output of the pipeline (eg, `autoview`)
Commands are separated by the pipe symbol (`|`) to denote a pipeline flowing left to right.
2019-06-15 02:24:13 +00:00
```
2019-07-15 20:19:40 +00:00
/home/jonathan/Source/nushell(master)> ls | where type == "Directory" | autoview
--------+-----------+----------+--------+--------------+----------------
name | type | readonly | size | accessed | modified
--------+-----------+----------+--------+--------------+----------------
target | Directory | | 4.1 KB | 19 hours ago | 19 hours ago
images | Directory | | 4.1 KB | 2 weeks ago | a week ago
tests | Directory | | 4.1 KB | 2 weeks ago | 18 minutes ago
docs | Directory | | 4.1 KB | a week ago | a week ago
.git | Directory | | 4.1 KB | 2 weeks ago | 25 minutes ago
src | Directory | | 4.1 KB | 2 weeks ago | 25 minutes ago
.cargo | Directory | | 4.1 KB | 2 weeks ago | 2 weeks ago
2019-06-15 02:24:13 +00:00
-----------+-----------+----------+--------+--------------+----------------
```
2019-06-15 04:20:58 +00:00
Because most of the time you'll want to see the output of a pipeline, `autoview` is assumed. We could have also written the above:
2019-06-15 02:24:13 +00:00
```
2019-07-15 20:19:40 +00:00
/home/jonathan/Source/nushell(master)> ls | where type == Directory
2019-06-15 02:24:13 +00:00
```
Being able to use the same commands and compose them differently is an important philosophy in Nu. For example, we could use the built-in `ps` command as well to get a list of the running processes, using the same `where` as above.
```text
C:\Code\nushell(master)> ps | where cpu > 0
------------------ +-----+-------+-------+----------
name | cmd | cpu | pid | status
------------------ +-----+-------+-------+----------
msedge.exe | - | 0.77 | 26472 | Runnable
nu.exe | - | 7.83 | 15473 | Runnable
SearchIndexer.exe | - | 82.17 | 23476 | Runnable
BlueJeans.exe | - | 4.54 | 10000 | Runnable
-------------------+-----+-------+-------+----------
```
## Opening files
Nu can load file and URL contents as raw text or as structured data (if it recognizes the format). For example, you can load a .toml file as structured data and explore it:
```
/home/jonathan/Source/nushell(master)> open Cargo.toml
-----------------+------------------+-----------------
2019-06-15 18:44:21 +00:00
dependencies | dev-dependencies | package
2019-06-15 02:24:13 +00:00
-----------------+------------------+-----------------
2019-06-15 18:44:21 +00:00
[object Object] | [object Object] | [object Object]
2019-06-15 02:24:13 +00:00
-----------------+------------------+-----------------
```
We can pipeline this into a command that gets the contents of one of the columns:
```
/home/jonathan/Source/nushell(master)> open Cargo.toml | get package
-------------+----------------------------+---------+---------+------+---------
2019-06-15 18:44:21 +00:00
authors | description | edition | license | name | version
2019-06-15 02:24:13 +00:00
-------------+----------------------------+---------+---------+------+---------
2019-06-15 18:44:21 +00:00
[list List] | A shell for the GitHub era | 2018 | MIT | nu | 0.1.2
2019-06-15 02:24:13 +00:00
-------------+----------------------------+---------+---------+------+---------
```
Finally, we can use commands outside of Nu once we have the data we want:
```
/home/jonathan/Source/nushell(master)> open Cargo.toml | get package.version | echo $it
0.1.2
```
Here we use the variable `$it` to refer to the value being piped to the external command.
2019-07-16 19:10:25 +00:00
## Plugins
2019-06-15 02:24:13 +00:00
2019-07-16 19:10:25 +00:00
Nu supports plugins that offer additional functionality to the shell and follow the same object model that built-in commands use. This allows you to extend nu for your needs.
2019-06-15 02:24:13 +00:00
2019-07-16 19:10:25 +00:00
There are a few examples in the `plugins` directory.
2019-06-15 02:24:13 +00:00
2019-07-16 19:10:25 +00:00
Plugins are binaries that are available in your path and follow a "nu_plugin_*" naming convention. These binaries interact with nu via a simple JSON-RPC protocol where the command identifies itself and passes along its configuration, which then makes it available for use. If the plugin is a filter, data streams to it one element at a time, and it can stream data back in return via stdin/stdout. If the plugin is a sink, it is given the full vector of final data and is given free reign over stdin/stdout to use as it pleases.
2019-06-15 02:24:13 +00:00
# Goals
Nu adheres closely to a set of goals that make up its design philosophy. As features are added, they are checked against these goals.
* First and foremost, Nu is cross-platform. Commands and techniques should carry between platforms and offer first-class consistent support for Windows, macOS, and Linux.
* Nu ensures direct compatibility with existing platform-specific executables that make up people's workflows.
* Nu's workflow and tools should have the usability in day-to-day experience of using a shell in 2019 (and beyond).
* Nu views data as both structured and unstructured. It is an object shell like PowerShell.
2019-07-16 19:10:25 +00:00
* Finally, Nu views data functionally. Rather than using mutation, pipelines act as a mean to load, change, and save data without mutable state.
2019-06-15 02:24:13 +00:00
# Commands
## Initial commands
2019-06-02 17:45:57 +00:00
| command | description |
2019-06-15 18:44:21 +00:00
| ------------- | ------------- |
2019-06-15 02:24:13 +00:00
| cd path | Change to a new path |
| ls (path) | View the contents of the current or given path |
2019-06-02 17:45:57 +00:00
| ps | View current processes |
2019-06-19 05:25:12 +00:00
| sysinfo | View information about the current system |
2019-06-15 02:24:13 +00:00
| open {filename or url} | Load a file into a cell, convert to table if possible (avoid by appending '--raw') |
2019-07-16 19:10:25 +00:00
| exit | Exit the shell |
2019-06-02 17:45:57 +00:00
2019-06-15 02:24:13 +00:00
## Filters on tables (structured data)
2019-06-02 17:45:57 +00:00
| command | description |
2019-06-15 18:44:21 +00:00
| ------------- | ------------- |
2019-06-02 18:53:30 +00:00
| pick ...columns | Down-select table to only these columns |
2019-06-02 17:49:08 +00:00
| reject ...columns | Remove the given columns from the table |
2019-06-05 01:57:16 +00:00
| get column-or-column-path | Open given cells as text |
2019-06-02 17:49:08 +00:00
| sort-by ...columns | Sort by the given columns |
2019-06-02 17:45:57 +00:00
| where condition | Filter table to match the condition |
| skip amount | Skip a number of rows |
| first amount | Show only the first number of rows |
| to-array | Collapse rows into a single list |
| to-json | Convert table into .json text |
| to-toml | Convert table into .toml text |
2019-07-16 19:10:25 +00:00
| to-yaml | Convert table into .yaml text |
2019-06-02 17:45:57 +00:00
2019-06-15 02:24:13 +00:00
## Filters on text (unstructured data)
2019-06-02 17:45:57 +00:00
| command | description |
2019-06-15 18:44:21 +00:00
| ------------- | ------------- |
2019-06-16 16:05:41 +00:00
| from-ini | Parse text as .ini and create table |
2019-06-02 17:45:57 +00:00
| from-json | Parse text as .json and create table |
| from-toml | Parse text as .toml and create table |
2019-06-11 06:36:31 +00:00
| from-xml | Parse text as .xml and create a table |
| from-yaml | Parse text as a .yaml/.yml and create a table |
2019-07-16 19:10:25 +00:00
| lines | Split single string into rows, one per line |
| size | Gather word count statistics on the text |
2019-06-02 19:04:30 +00:00
| split-column sep ...fields | Split row contents across multiple columns via the separator |
2019-06-02 17:45:57 +00:00
| split-row sep | Split row contents over multiple rows via the separator |
| trim | Trim leading and following whitespace from text data |
2019-06-15 18:44:21 +00:00
| {external-command} $it | Run external command with given arguments, replacing $it with each row text |
2019-05-17 16:59:25 +00:00
2019-06-15 02:24:13 +00:00
## Consuming commands
| command | description |
2019-06-15 18:44:21 +00:00
| ------------- | ------------- |
2019-06-15 02:24:13 +00:00
| autoview | View the contents of the pipeline as a table or list |
2019-07-16 19:10:25 +00:00
| binaryview | Autoview of binary data |
2019-06-15 04:20:58 +00:00
| clip | Copy the contents of the pipeline to the copy/paste buffer |
2019-06-15 02:24:13 +00:00
| save filename | Save the contents of the pipeline to a file |
2019-06-21 04:36:36 +00:00
| table | View the contents of the pipeline as a table |
2019-06-15 02:24:13 +00:00
| tree | View the contents of the pipeline as a tree |
2019-06-21 04:36:36 +00:00
| vtable | View the contents of the pipeline as a vertical (rotated) table |
2019-05-17 16:59:25 +00:00
2019-06-02 16:49:56 +00:00
# License
The project is made available under the MIT license. See "LICENSE" for more information.