nushell/README.md

344 lines
19 KiB
Markdown
Raw Normal View History

2019-09-02 01:43:30 +00:00
[![Crates.io](https://img.shields.io/crates/v/nu.svg)](https://crates.io/crates/nu)
2019-09-28 01:46:57 +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)
2019-09-02 01:43:30 +00:00
[![Discord](https://img.shields.io/discord/601130461678272522.svg?logo=discord)](https://discord.gg/NtAbbGn)
2019-10-02 14:34:08 +00:00
[![The Changelog #363](https://img.shields.io/badge/The%20Changelog-%23363-61c192.svg)](https://changelog.com/podcast/363)
2019-09-02 01:43:30 +00:00
2019-09-28 01:46:57 +00:00
2019-05-17 16:59:25 +00:00
# Nu Shell
2019-10-01 11:00:00 +00:00
A modern shell for the GitHub era.
2019-05-17 16:59:25 +00:00
2019-09-23 07:59:05 +00:00
![Example of nushell](images/nushell-autocomplete.gif "Example of nushell")
2019-08-23 05:23:53 +00:00
2019-05-17 16:59:25 +00:00
# Status
2019-09-30 22:51:35 +00:00
This project has reached a minimum-viable product level of quality. While contributors dogfood it as their daily driver, it may be unstable for some commands. Future releases will work to fill out missing features and improve stability. Its design is also subject to change as it matures.
2019-05-17 16:59:25 +00:00
2019-10-01 10:54:59 +00: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 16:59:25 +00:00
2019-09-13 03:04:14 +00:00
# Learning more
2019-12-15 12:56:26 +00:00
There are a few good resources to learn about Nu. There is a [book](https://www.nushell.sh/book/) about Nu that is currently in progress. The book focuses on using Nu and its core concepts.
2019-09-13 03:04:14 +00:00
2019-12-15 12:56:26 +00:00
If you're a developer who would like to contribute to Nu, we're also working on a [book for developers](https://www.nushell.sh/contributor-book/) to help you get started. There are also [good first issues](https://github.com/nushell/nushell/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) to help you dive in.
2019-09-13 03:04:14 +00:00
2019-10-01 10:54:59 +00:00
We also have an active [Discord](https://discord.gg/NtAbbGn) and [Twitter](https://twitter.com/nu_shell) if you'd like to come and chat with us.
2019-09-29 22:29:59 +00:00
2019-10-01 11:39:18 +00:00
Try it in Gitpod.
2019-09-29 22:29:59 +00:00
2019-09-28 01:46:57 +00:00
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/nushell/nushell)
2019-08-18 03:27:03 +00:00
2019-08-23 04:03:07 +00:00
# Installation
2019-09-28 01:46:57 +00:00
## Local
2019-12-15 12:56:26 +00:00
Up-to-date installation instructions can be found in the [installation chapter of the book](https://www.nushell.sh/book/en/installation.html). **Windows users**: please note that Nu works on Windows 10 and does not currently have Windows 7/8.1 support.
2019-08-23 04:03:07 +00:00
2019-11-07 18:17:12 +00:00
To build Nu, you will need to use the **latest stable (1.39 or later)** version of the compiler.
2019-08-24 16:38:11 +00:00
2019-08-23 15:32:28 +00:00
Required dependencies:
* pkg-config and libssl (only needed on Linux)
* on Debian/Ubuntu: `apt install pkg-config libssl-dev`
2019-08-23 15:32:28 +00:00
2019-08-23 15:39:50 +00:00
Optional dependencies:
2019-08-23 15:32:28 +00: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-11-07 19:19:41 +00:00
To install Nu via cargo (make sure you have installed [rustup](https://rustup.rs/) and the latest stable compiler via `rustup install stable`):
2019-08-23 15:27:52 +00:00
```
2019-11-07 18:17:12 +00:00
cargo install nu
2019-08-23 15:27:52 +00:00
```
2019-12-15 12:56:26 +00:00
You can also install Nu with all the bells and whistles (be sure to have installed the [dependencies](https://www.nushell.sh/book/en/installation.html#dependencies) for your platform):
2019-08-23 15:27:52 +00:00
```
cargo install nu --features=stable
2019-08-23 15:27:52 +00:00
```
## Docker
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:
```bash
$ 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-09-28 01:46:57 +00:00
```
And then to build the smaller container (using a Multistage build):
```bash
$ docker build -f docker/Dockerfile -t nushell/nu .
2019-09-28 01:46:57 +00:00
```
Either way, you can run either container as follows:
```bash
$ docker run -it nushell/nu-base
$ docker run -it nushell/nu
/> exit
```
2019-10-01 10:58:56 +00:00
The second container is a bit smaller if the size is important to you.
2019-09-06 20:05:35 +00:00
## Packaging status
[![Packaging status](https://repology.org/badge/vertical-allrepos/nushell.svg)](https://repology.org/project/nushell/versions)
2019-09-06 20:05:35 +00:00
### Fedora
[COPR repo](https://copr.fedorainfracloud.org/coprs/atim/nushell/): `sudo dnf copr enable atim/nushell -y && sudo dnf install nushell -y`
2019-06-15 02:24:13 +00:00
# Philosophy
2019-10-01 10:54:59 +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 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 02:24:13 +00:00
## Pipelines
2019-10-01 11:44:06 +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-10-01 11:46:04 +00:00
* Commands that consume the output of the pipeline (eg, `autoview`)
2019-06-15 04:20:58 +00:00
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
━━━━┯━━━━━━━━━━━┯━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━
2019-09-28 01:46:57 +00:00
# │ name │ type │ readonly │ size │ accessed │ modified
────┼───────────┼───────────┼──────────┼────────┼──────────────┼────────────────
2019-09-28 01:46:57 +00:00
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-09-28 01:46:57 +00:00
━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━
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
/home/jonathan/Source/nushell(master)> ps | where cpu > 0
━━━┯━━━━━━━┯━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━
2019-09-28 01:46:57 +00:00
# │ pid │ name │ status │ cpu
───┼───────┼─────────────────┼──────────┼──────────
2019-09-28 01:46:57 +00:00
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 02:24:13 +00: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-28 01:46:57 +00:00
bin │ dependencies │ dev-dependencies
──────────────────┼────────────────┼──────────────────
2019-09-28 01:46:57 +00:00
[table: 12 rows] │ [table: 1 row] │ [table: 1 row]
━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━
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-09-28 01:46:57 +00:00
authors │ description │ edition │ license │ name │ version
─────────────────┼────────────────────────────┼─────────┼─────────┼──────┼─────────
2019-11-30 18:12:14 +00:00
[table: 3 rows] │ A shell for the GitHub era │ 2018 │ MIT │ nu │ 0.6.1
━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━┷━━━━━━━━━┷━━━━━━┷━━━━━━━━━
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
2019-11-30 18:12:14 +00:00
0.6.1
2019-06-15 02:24:13 +00:00
```
Here we use the variable `$it` to refer to the value being piped to the external command.
2019-11-18 14:41:16 +00:00
## Configuration
Nu has early support for configuring the shell. It currently supports the following settings:
| Variable | Type | Description |
| ------------- | ------------- | ----- |
| path | table of strings | PATH to use to find binaries |
| env | row | the environment variables to pass to external commands |
| ctrlc_exit | boolean | whether or not to exit Nu after multiple ctrl-c presses |
| table_mode | "light" or other | enable lightweight or normal tables |
| edit_mode | "vi" or "emacs" | changes line editing to "vi" or "emacs" mode |
To set one of these variables, you can use `config --set`. For example:
```
> config --set [edit_mode "vi"]
> config --set [path $nu:path]
```
2019-08-07 17:49:11 +00:00
## Shells
2019-09-28 01:46:57 +00:00
Nu will work inside of a single directory and allow you to navigate around your filesystem by default. Nu also offers a way of adding additional working directories that you can jump between, allowing you to work in multiple directories at the same time.
2019-08-07 17:49:11 +00:00
2019-08-08 01:50:45 +00: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 17:49:11 +00:00
Finally, to get a list of all the current shells, you can use the `shells` command.
2019-06-15 02:24:13 +00:00
2019-07-16 19:10:25 +00:00
## Plugins
2019-06-15 02:24:13 +00: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 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-10-15 05:52:15 +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 a structured shell like PowerShell.
2019-06-15 02:24:13 +00:00
2019-08-24 21:48:02 +00: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 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 |
2019-07-22 02:23:02 +00:00
| cp source path | Copy files |
2019-09-23 03:55:52 +00:00
| date (--utc) | Get the current datetime |
| fetch url | Fetch contents from a url and retrieve data as a table if possible |
| help | Display help information about commands |
2019-06-15 02:24:13 +00:00
| ls (path) | View the contents of the current or given path |
| mkdir path | Make directories, creates intermediary directories as required. |
2019-08-14 20:08:10 +00:00
| mv source target | Move files or directories. |
2019-09-23 03:55:52 +00:00
| open filename | Load a file into a cell, convert to table if possible (avoid by appending '--raw') |
| post url body (--user <user>) (--password <password>) | Post content to a url and retrieve data as a table if possible |
2019-06-02 17:45:57 +00:00
| ps | View current processes |
2019-07-28 02:02:42 +00:00
| sys | View information about the current system |
| which filename | Finds a program file. |
2019-07-17 19:51:18 +00:00
| rm {file or directory} | Remove a file, (for removing directory append '--recursive') |
2019-09-23 03:55:52 +00:00
| version | Display Nu version |
## Shell commands
| command | description |
| ------- | ----------- |
2019-08-07 17:49:11 +00: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-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-10-30 07:22:01 +00:00
| append row-data | Append a row to the end of the table |
2019-11-23 23:57:12 +00:00
| compact ...columns | Remove rows where given columns are empty |
| count | Show the total number of rows |
2019-11-24 09:20:08 +00:00
| default column row-data | Sets a default row's column if missing |
| edit column-or-column-path value | Edit an existing column to have a new value |
2019-09-23 03:55:52 +00:00
| embed column | Creates a new table of one column with the given name, and places the current table inside of it |
2019-06-02 17:45:57 +00:00
| first amount | Show only the first number of rows |
2019-11-10 00:16:52 +00:00
| format pattern | Format table row data as a string following the given pattern |
2019-09-23 03:55:52 +00:00
| get column-or-column-path | Open column and get data from the corresponding cells |
2019-10-20 23:42:07 +00:00
| group-by column | Creates a new table with the data from the table rows grouped by the column given |
| histogram column ...column-names | Creates a new table with a histogram based on the column name passed in, optionally give the frequency column name
2019-09-23 03:55:52 +00:00
| inc (column-or-column-path) | Increment a value or version. Optionally use the column of a table |
2019-11-02 01:48:18 +00:00
| insert column-or-column-path value | Insert a new column to the table |
| last amount | Show only the last number of rows |
| nth ...row-numbers | Return only the selected rows |
2019-09-23 03:55:52 +00:00
| pick ...columns | Down-select table to only these columns |
2019-09-17 07:33:52 +00:00
| pivot --header-row <headers> | Pivot the tables, making columns into rows and vice versa |
2019-10-30 07:22:01 +00:00
| prepend row-data | Prepend a row to the beginning of the table |
2019-09-23 03:55:52 +00:00
| reject ...columns | Remove the given columns from the table |
| reverse | Reverses the table. |
| skip amount | Skip a number of rows |
2019-11-23 23:57:12 +00:00
| skip-while condition | Skips rows while the condition matches |
| split-by column | Creates a new table with the data from the inner tables splitted by the column given |
2019-09-23 03:55:52 +00:00
| sort-by ...columns | Sort by the given columns |
| str (column) | Apply string function. Optionally use the column of a table |
2019-09-23 03:55:52 +00:00
| sum | Sum a column of values |
| tags | Read the tags (metadata) for values |
2019-09-23 03:55:52 +00:00
| to-bson | Convert table into .bson binary data |
| to-csv | Convert table into .csv text |
2019-06-02 17:45:57 +00:00
| to-json | Convert table into .json text |
2019-09-23 03:55:52 +00:00
| to-sqlite | Convert table to sqlite .db binary data |
2019-06-02 17:45:57 +00:00
| to-toml | Convert table into .toml text |
2019-08-31 05:14:04 +00:00
| to-tsv | Convert table into .tsv text |
2019-09-23 03:52:01 +00:00
| to-url | Convert table to a urlencoded string |
2019-09-23 03:55:52 +00:00
| to-yaml | Convert table into .yaml text |
| where condition | Filter table to match the condition |
2019-08-31 05:14:04 +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-08-31 05:14:04 +00:00
| from-bson | Parse binary data as .bson and create table |
| from-csv | Parse text as .csv and create table |
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 |
2019-08-31 05:14:04 +00:00
| from-sqlite | Parse binary data as sqlite .db and create table |
2019-10-15 21:19:16 +00:00
| from-ssv --minimum-spaces <minimum number of spaces to count as a separator> | Parse text as space-separated values and create table |
2019-06-02 17:45:57 +00:00
| from-toml | Parse text as .toml and create table |
| from-tsv | Parse text as .tsv and create table |
2019-09-23 03:52:01 +00:00
| from-url | Parse urlencoded string and create a 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 |
2019-11-09 22:27:56 +00:00
| parse pattern | Convert text to a table by matching the given pattern |
2019-07-16 19:10:25 +00:00
| size | Gather word count statistics on the text |
| split-column sep ...column-names | Split row contents across multiple columns via the separator, optionally give the columns names |
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-09-23 03:55:52 +00:00
| binaryview | Autoview of binary data (optional feature) |
| clip | Copy the contents of the pipeline to the copy/paste buffer (optional feature) |
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-08-23 15:39:30 +00:00
| textview | Autoview of text data |
2019-09-23 03:55:52 +00:00
| tree | View the contents of the pipeline as a tree (optional feature) |
2019-06-02 16:49:56 +00:00
# License
The project is made available under the MIT license. See "LICENSE" for more information.