2019-09-02 03:43:30 +02:00
[![Crates.io ](https://img.shields.io/crates/v/nu.svg )](https://crates.io/crates/nu)
[![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-07-17 22:13:09 +02:00
2019-05-17 18:59:25 +02:00
# Nu Shell
2019-08-30 03:39:20 +02:00
A modern shell for the GitHub era
2019-05-17 18:59:25 +02:00
2019-08-23 07:23:53 +02:00
![Example of nushell ](images/nushell-autocomplete4.gif "Example of nushell" )
2019-05-17 18:59:25 +02:00
# Status
2019-08-23 23:03:39 +02:00
This project has reached a minimum-viable product level of quality. While contributors dogfood it as their daily driver, it may be instable for some commands. Future releases will work fill out missing features and improve stability. Its design is also subject to change as it matures.
2019-05-17 18:59:25 +02:00
2019-08-23 23:03:39 +02:00
Nu comes with a set 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 18:59:25 +02:00
2019-08-23 22:37:44 +02:00
There is also a [book ](https://book.nushell.sh ) about Nu, currently in progress.
2019-08-18 05:27:03 +02:00
2019-08-23 06:03:07 +02:00
# Installation
2019-08-25 22:16:02 +02:00
## Local
2019-08-23 06:03:07 +02:00
Up-to-date installation instructions can be found in the [installation chapter of the book ](https://book.nushell.sh/en/installation ).
2019-08-24 18:38:11 +02:00
To build Nu, you will need to use the **nightly** version of the compiler.
2019-08-23 17:32:28 +02:00
Required dependencies:
2019-09-03 20:26:18 +02:00
* pkg-config and libssl (only needed on Linux)
* on Debian/Ubuntu: `apt install pkg-config libssl-dev`
2019-08-23 17:32:28 +02:00
2019-08-23 17:39:50 +02:00
Optional dependencies:
2019-08-23 17:32:28 +02:00
* To use Nu with all possible optional features enabled, you'll also need the following:
* on Linux (on Debian/Ubuntu): `apt install libxcb-composite0-dev libx11-dev`
2019-08-23 17:27:52 +02:00
To install Nu via cargo:
```
2019-08-26 00:45:12 +02:00
cargo +nightly install nu
2019-08-23 17:27:52 +02:00
```
You can also install Nu with all the bells and whistles:
```
2019-08-29 01:32:58 +02:00
cargo +nightly install nu --features raw-key,clipboard
2019-08-23 17:27:52 +02:00
```
The following optional features are currently supported:
2019-08-29 01:32:58 +02:00
* **raw-key** - direct keyboard input, which creates a smoother experience in viewing text and binaries
2019-08-23 17:27:52 +02:00
* **clipboard** - integration with the native clipboard via the `clip` command
2019-08-25 22:16:02 +02:00
## Docker
2019-08-30 00:38:53 +02:00
If you want to pull a pre-built container, you can browse tags for the [nushell organization ](https://quay.io/organization/nushell )
on Quay.io. Pulling a container would come down to:
2019-08-25 22:16:02 +02:00
```bash
2019-08-30 00:38:53 +02:00
$ docker pull quay.io/nushell/nu
$ docker pull quay.io/nushell/nu-base
```
Both "nu-base" and "nu" provide the nu binary, however nu-base also includes the source code at `/code`
in the container and all dependencies.
Optionally, you can also build the containers locally using the [dockerfiles provided ](docker ):
To build the base image:
```bash
$ docker build -f docker/Dockerfile.nu-base -t nushell/nu-base .
2019-08-25 22:16:02 +02:00
```
2019-08-30 00:38:53 +02:00
And then to build the smaller container (using a Multistage build):
2019-08-25 22:16:02 +02:00
```bash
2019-08-30 00:38:53 +02:00
$ docker build -f docker/Dockerfile -t nushell/nu .
```
Either way, you can run either container as follows:
```bash
$ docker run -it nushell/nu-base
$ docker run -it nushell/nu
2019-08-25 22:16:02 +02:00
/> exit
```
2019-08-30 00:38:53 +02:00
The second container is a bit smaller, if size is important to you.
2019-06-15 04:24:13 +02:00
# Philosophy
2019-09-04 18:29:49 +02: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 is a table of rows, where each row 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 04:24:13 +02:00
## Pipelines
2019-07-12 19:39:55 +02: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 04:24:13 +02:00
2019-06-15 06:20:58 +02:00
* Commands that produce a stream (eg, `ls` )
2019-07-16 21:10:25 +02:00
* Commands that filter a stream (eg, `where type == "Directory"` )
2019-06-15 06:20:58 +02: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 04:24:13 +02:00
```
2019-07-15 22:19:40 +02:00
/home/jonathan/Source/nushell(master)> ls | where type == "Directory" | autoview
2019-09-04 18:29:49 +02:00
━━━━┯━━━━━━━━━━━┯━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━
# │ name │ type │ readonly │ size │ accessed │ modified
────┼───────────┼───────────┼──────────┼────────┼──────────────┼────────────────
0 │ .azure │ Directory │ │ 4.1 KB │ 2 months ago │ a day ago
1 │ target │ Directory │ │ 4.1 KB │ 3 days ago │ 3 days ago
2 │ images │ Directory │ │ 4.1 KB │ 2 months ago │ 2 weeks ago
3 │ tests │ Directory │ │ 4.1 KB │ 2 months ago │ 37 minutes ago
4 │ tmp │ Directory │ │ 4.1 KB │ 2 weeks ago │ 2 weeks ago
5 │ src │ Directory │ │ 4.1 KB │ 2 months ago │ 37 minutes ago
6 │ assets │ Directory │ │ 4.1 KB │ a month ago │ a month ago
7 │ docs │ Directory │ │ 4.1 KB │ 2 months ago │ 2 months ago
━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━
2019-06-15 04:24:13 +02:00
```
2019-06-15 06:20:58 +02: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 04:24:13 +02:00
```
2019-07-15 22:19:40 +02:00
/home/jonathan/Source/nushell(master)> ls | where type == Directory
2019-06-15 04:24:13 +02: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
2019-09-04 18:29:49 +02:00
/home/jonathan/Source/nushell(master)> ps | where cpu > 0
━━━┯━━━━━━━┯━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━
# │ pid │ name │ status │ cpu
───┼───────┼─────────────────┼──────────┼──────────
0 │ 992 │ chrome │ Sleeping │ 6.988768
1 │ 4240 │ chrome │ Sleeping │ 5.645982
2 │ 13973 │ qemu-system-x86 │ Sleeping │ 4.996551
3 │ 15746 │ nu │ Sleeping │ 84.59905
━━━┷━━━━━━━┷━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━
2019-06-15 04:24:13 +02:00
```
## 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-09-04 18:29:49 +02:00
━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━
bin │ dependencies │ dev-dependencies
──────────────────┼────────────────┼──────────────────
[table: 12 rows] │ [table: 1 row] │ [table: 1 row]
━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━
2019-06-15 04:24:13 +02: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-09-04 18:29:49 +02:00
━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━┯━━━━━━━━━┯━━━━━━┯━━━━━━━━━
authors │ description │ edition │ license │ name │ version
─────────────────┼────────────────────────────┼─────────┼─────────┼──────┼─────────
[table: 3 rows] │ A shell for the GitHub era │ 2018 │ ISC │ nu │ 0.2.0
━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━┷━━━━━━┷━━━━━━━━━
2019-06-15 04:24:13 +02: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
2019-08-23 17:34:36 +02:00
0.2.0
2019-06-15 04:24:13 +02:00
```
Here we use the variable `$it` to refer to the value being piped to the external command.
2019-08-07 19:49:11 +02:00
## Shells
2019-08-08 03:50:45 +02:00
By default, Nu will work inside of a single directory and allow you to navigate around your filesystem. Sometimes, you'll want to work in multiple directories at the same time. For this, Nu offers a way of adding additional working directories that you can jump between.
2019-08-07 19:49:11 +02:00
2019-08-08 03:50:45 +02:00
To do so, use the `enter` command, which will allow you create a new "shell" and enter it at the specified path. You can toggle between this new shell and the original shell with the `p` (for previous) and `n` (for next), allowing you to navigate around a ring buffer of shells. Once you're done with a shell, you can `exit` it and remove it from the ring buffer.
2019-08-07 19:49:11 +02:00
Finally, to get a list of all the current shells, you can use the `shells` command.
2019-06-15 04:24:13 +02:00
2019-07-16 21:10:25 +02:00
## Plugins
2019-06-15 04:24:13 +02:00
2019-09-04 18:29:49 +02:00
Nu supports plugins that offer additional functionality to the shell and follow the same structured data model that built-in commands use. This allows you to extend nu for your needs.
2019-06-15 04:24:13 +02:00
2019-07-16 21:10:25 +02:00
There are a few examples in the `plugins` directory.
2019-06-15 04:24:13 +02:00
2019-07-16 21:10:25 +02: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 04:24:13 +02: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).
2019-09-04 18:29:49 +02:00
* Nu views data as both structured and unstructured. It is a structured shell like PowerShell.
2019-06-15 04:24:13 +02:00
2019-08-24 23:48:02 +02:00
* Finally, Nu views data functionally. Rather than using mutation, pipelines act as a means to load, change, and save data without mutable state.
2019-06-15 04:24:13 +02:00
# Commands
## Initial commands
2019-06-02 19:45:57 +02:00
| command | description |
2019-06-15 20:44:21 +02:00
| ------------- | ------------- |
2019-06-15 04:24:13 +02:00
| cd path | Change to a new path |
2019-07-22 04:23:02 +02:00
| cp source path | Copy files |
2019-06-15 04:24:13 +02:00
| ls (path) | View the contents of the current or given path |
2019-08-07 21:38:00 +02:00
| mkdir path | Make directories, creates intermediary directories as required. |
2019-08-14 22:08:10 +02:00
| mv source target | Move files or directories. |
2019-07-26 06:09:19 +02:00
| date (--utc) | Get the current datetime |
2019-06-02 19:45:57 +02:00
| ps | View current processes |
2019-07-28 04:02:42 +02:00
| sys | View information about the current system |
2019-08-30 00:52:32 +02:00
| which filename | Finds a program file. |
2019-09-03 08:04:46 +02:00
| open filename | Load a file into a cell, convert to table if possible (avoid by appending '--raw') |
| fetch url | Fetch contents from a url and retrieve data as a table if possible |
2019-08-31 07:14:04 +02:00
| post url body (--user < user > ) (--password < password > ) | Post content to a url and retrieve data as a table if possible |
2019-07-17 21:51:18 +02:00
| rm {file or directory} | Remove a file, (for removing directory append '--recursive') |
2019-08-07 19:49:11 +02:00
| exit (--now) | Exit the current shell (or all shells) |
| enter (path) | Create a new shell and begin at this path |
| p | Go to previous shell |
| n | Go to next shell |
| shells | Display the list of current shells |
2019-08-30 00:52:32 +02:00
| help | Display help information about commands |
| version | Display Nu version |
2019-06-02 19:45:57 +02:00
2019-06-15 04:24:13 +02:00
## Filters on tables (structured data)
2019-06-02 19:45:57 +02:00
| command | description |
2019-06-15 20:44:21 +02:00
| ------------- | ------------- |
2019-06-02 20:53:30 +02:00
| pick ...columns | Down-select table to only these columns |
2019-06-02 19:49:08 +02:00
| reject ...columns | Remove the given columns from the table |
2019-08-31 08:12:08 +02:00
| get column-or-column-path | Open column and get data from the corresponding cells |
2019-08-28 05:06:22 +02:00
| sort-by ...columns | Sort by the given columns |
2019-06-02 19:45:57 +02:00
| where condition | Filter table to match the condition |
2019-09-04 18:29:49 +02:00
| inc (column-or-column-path) | Increment a value or version. Optionally use the column of a table |
| add column-or-column-path value | Add a new column to the table |
| embed column | Creates a new table of one column with the given name, and places the current table inside of it |
2019-07-27 18:44:32 +02:00
| sum | Sum a column of values |
2019-09-04 18:29:49 +02:00
| edit column-or-column-path value | Edit an existing column to have a new value |
2019-08-30 00:52:32 +02:00
| reverse | Reverses the table. |
2019-06-02 19:45:57 +02:00
| skip amount | Skip a number of rows |
2019-08-30 00:52:32 +02:00
| skip-while condition | Skips rows while the condition matches. |
2019-06-02 19:45:57 +02:00
| first amount | Show only the first number of rows |
2019-08-30 00:52:32 +02:00
| last amount | Show only the last number of rows |
2019-08-12 07:19:22 +02:00
| nth row-number | Return only the selected row |
2019-09-04 18:29:49 +02:00
| str (column) | Apply string function. Optionally use the column of a table |
2019-08-01 05:25:59 +02:00
| tags | Read the tags (metadata) for values |
2019-06-02 19:45:57 +02:00
| to-json | Convert table into .json text |
| to-toml | Convert table into .toml text |
2019-07-16 21:10:25 +02:00
| to-yaml | Convert table into .yaml text |
2019-08-30 00:52:32 +02:00
| to-bson | Convert table into .bson text |
2019-09-02 07:37:13 +02:00
| to-csv | Convert table into .csv text |
2019-08-31 07:14:04 +02:00
| to-bson | Convert table into .bson binary data |
| to-tsv | Convert table into .tsv text |
| to-sqlite | Convert table to sqlite .db binary data |
2019-06-15 04:24:13 +02:00
## Filters on text (unstructured data)
2019-06-02 19:45:57 +02:00
| command | description |
2019-06-15 20:44:21 +02:00
| ------------- | ------------- |
2019-08-31 07:14:04 +02:00
| from-bson | Parse binary data as .bson and create table |
2019-07-19 22:11:49 +02:00
| from-csv | Parse text as .csv and create table |
2019-06-16 18:05:41 +02:00
| from-ini | Parse text as .ini and create table |
2019-06-02 19:45:57 +02:00
| from-json | Parse text as .json and create table |
2019-08-31 07:14:04 +02:00
| from-sqlite | Parse binary data as sqlite .db and create table |
2019-06-02 19:45:57 +02:00
| from-toml | Parse text as .toml and create table |
2019-08-30 00:52:32 +02:00
| from-tsv | Parse text as .tsv and create table |
2019-06-11 08:36:31 +02: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 21:10:25 +02:00
| lines | Split single string into rows, one per line |
| size | Gather word count statistics on the text |
2019-09-04 18:29:49 +02:00
| split-column sep ...column-names | Split row contents across multiple columns via the separator, optionally give the columns names |
2019-06-02 19:45:57 +02: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 20:44:21 +02:00
| {external-command} $it | Run external command with given arguments, replacing $it with each row text |
2019-05-17 18:59:25 +02:00
2019-06-15 04:24:13 +02:00
## Consuming commands
| command | description |
2019-06-15 20:44:21 +02:00
| ------------- | ------------- |
2019-06-15 04:24:13 +02:00
| autoview | View the contents of the pipeline as a table or list |
2019-07-16 21:10:25 +02:00
| binaryview | Autoview of binary data |
2019-06-15 06:20:58 +02:00
| clip | Copy the contents of the pipeline to the copy/paste buffer |
2019-06-15 04:24:13 +02:00
| save filename | Save the contents of the pipeline to a file |
2019-06-21 06:36:36 +02:00
| table | View the contents of the pipeline as a table |
2019-08-23 17:39:30 +02:00
| textview | Autoview of text data |
2019-06-15 04:24:13 +02:00
| tree | View the contents of the pipeline as a tree |
2019-06-21 06:36:36 +02:00
| vtable | View the contents of the pipeline as a vertical (rotated) table |
2019-05-17 18:59:25 +02:00
2019-06-02 18:49:56 +02:00
# License
The project is made available under the MIT license. See "LICENSE" for more information.