Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,43 @@ module.exports = {
],
},
],
},
sidebar: {
"/old_book/": [
{
title: "Nu Book (old)",
collapsable: false,
children: [
"",
"installation",
"moving_around",
"types_of_data",
"loading_data",
"working_with_lists",
"working_with_tables",
"pipeline",
"configuration",
"custom_commands",
"aliases",
"operators",
"math",
"variables_and_subexpressions",
"environment",
"scripts",
"metadata",
"shells_in_shells",
"escaping",
"plugins",
"dataframes",
"coming_from_bash",
"nushell_map",
"nushell_map_imperative",
"nushell_map_functional",
"nushell_operator_map",
"command_reference",
],
},
],
"/contributor-book/": [
{
title: "Contributor Book",
Expand Down
73 changes: 73 additions & 0 deletions old_book/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Introduction

Hello, and welcome to the Nushell project. The goal of this project is to take the Unix philosophy of shells, where pipes connect simple commands together, and bring it to the modern style of development.

Nu takes cues from a lot of familiar territory: traditional shells like bash, object based shells like PowerShell, functional programming, systems programming, and more. But rather than trying to be the jack of all trades, Nu focuses its energy on doing a few things well:

* Create a flexible cross-platform shell with a modern feel
* Allow you to mix and match commandline applications with a shell that understands the structure of your data
* Have the level of UX polish that modern CLI apps provide

The easiest way to see what Nu can do is to start with some examples, so let's dive in.

The first thing you'll notice when you run a command like `ls` is that instead of a block of text coming back, you get a structured table.

<<< @/snippets/introduction/ls_example.sh

The table is more than just showing the directory in a different way. Just like tables in a spreadsheet, this table allows us to work with the data more interactively.

The first thing we'll do is to sort our table by the size. To do this, we'll take the output from `ls` and feed it into a command that can sort tables based on the contents of a column.

<<< @/snippets/introduction/ls_sort_by_reverse_example.sh

You can see that to make this work we didn't pass commandline arguments to `ls`. Instead, we used the `sort-by` command that Nu provides to do the sorting of the output of the `ls` command. To see the biggest files on top, we also used `reverse`.

Nu provides many commands that can work on tables. For example, we could filter the contents of the `ls` table so that it only shows files over 1 kilobyte:

<<< @/snippets/introduction/ls_where_example.sh

Just as in the Unix philosophy, being able to have commands talk to each other gives us ways to mix-and-match in many different combinations. Let's look at a different command:

<<< @/snippets/introduction/ps_example.sh

You may be familiar with the `ps` command if you've used Linux. With it, we can get a list of all the current processes that the system is running, what their status is, and what their name is. We can also see the CPU load for the processes.

What if we wanted to show the processes that were actively using the CPU? Just like we did with the `ls` command earlier, we can also work with the table that the `ps` command gives back to us:

<<< @/snippets/introduction/ps_where_example.sh

So far, we've been using `ls` and `ps` to list files and processes. Nu also offers other commands that can create tables of useful information. Next, let's explore `date` and `sys`.

Running `date now` gives us information about the current day and time:

<<< @/snippets/introduction/date_example.sh

To get the date as a table we can feed it into `date to-table`

<<< @/snippets/introduction/date_table_example.sh

Running `sys` gives information about the system that Nu is running on:

<<< @/snippets/introduction/sys_example.sh

This is a bit different than the tables we saw before. The `sys` command gives us a table that contains structured tables in the cells instead of simple values. To take a look at this data, we need to *get* the column to view:

<<< @/snippets/introduction/sys_get_example.sh

The `get` command lets us jump into the contents of a column of the table. Here, we're looking into the "host" column, which contains information about the host that Nu is running on. The name of the OS, the hostname, the CPU, and more. Let's get the name of the users on the system:

<<< @/snippets/introduction/sys_get_nested_example.sh

Right now, there's just one user on the system named "jt". You'll notice that we can pass a column path (the `host.sessions` part) and not just the name of the column. Nu will take the column path and go to the corresponding bit of data in the table.

You might have noticed something else that's different. Rather than having a table of data, we have just a single element: the string "jt". Nu works with both tables of data as well as strings. Strings are an important part of working with commands outside of Nu.

Let's see how strings work outside of Nu in action. We'll take our example from before and run the external `echo` command (the `^` tells Nu to not use the built-in `echo` command):

<<< @/snippets/introduction/sys_get_external_echo_example.sh

If this looks very similar to what we had before, you have a keen eye! It is similar, but with one important difference: we've called `^echo` with the value we saw earlier. This allows us to pass data out of Nu into `echo` (or any command outside of Nu, like `git` for example).

*Note: help text for any of Nu's builtin commands can be discovered with the `help` command*:

<<< @/snippets/introduction/help_example.sh
27 changes: 27 additions & 0 deletions old_book/aliases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Aliases

Aliases in Nushell offer a way of doing a simple, textual replacement. This allows you to create a shorthand name for a longer command, including its default arguments.

For example, let's create an alias called `ll` which will expand to `ls -l`.

```
> alias ll = ls -l
```

We can now call this alias:

```
> ll
```

Once we do, it's as if we typed `ls -l`. This also allows us to pass in flags or positional parameters. For example, we can now also write:

```
> ll -a
```

And get the equivalent to having typed `ls -l -a`.

## Persisting

For information about how to persist aliases so that they're visible when you start up Nushell, see the [configuration chapter](configuration.md#startup-commands) and add your aliases to the `startup` section.
51 changes: 51 additions & 0 deletions old_book/coming_from_bash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Coming from Bash

Note: this table assumes Nu 0.14.1 or later.

| Bash | Nu | Task |
| ------------- | ------------- | ----- |
| `ls` | `ls` | Lists the files in the current directory |
| `ls <dir>` | `ls <dir>`| Lists the files in the given directory |
| `ls pattern*` | `ls pattern*` | Lists files that match a given pattern |
| `ls -la` | `ls --long --all` or `ls -la` | List files with all available information, including hidden files |
| `ls -d */` | `ls | where type == Dir` | List directories |
| `find . -name *.rs` | `ls **/*.rs` | Find recursively all files that match a given pattern |
| `cd <directory>` | `cd <directory>` | Change to the given directory |
| `cd` | `cd` | Change to the home directory |
| `mkdir <path>` | `mkdir <path>` | Creates the given path |
| `mkdir -p <path>` | `mkdir <path>` | Creates the given path, creating parents as necessary |
| `touch test.txt` | `touch test.txt` | Create a file |
| `> <path>` | `| save --raw <path>` | Save string into a file |
| `>> <path>` | `| save --raw --append <path>` | Append string to a file |
| `cat <path>` | `open --raw <path>` | Display the contents of the given file |
| | `open <path>` | Read a file as structured data |
| `mv <source> <dest>` | `mv <source> <dest>` | Move file to new location |
| `cp <source> <dest>` | `cp <source> <dest>` | Copy file to new location |
| `cp -r <source> <dest>` | `cp -r <source> <dest>` | Copy directory to a new location, recursively |
| `rm <path>` | `rm <path>` | Remove the given file |
| | `rm -t <path>` | Move the given file to the system trash |
| `rm -rf <path>` | `rm -r <path>` | Recursively removes the given path |
| `chmod` | `<not yet possible>` | Changes the file attributes |
| `date -d <date>` | `echo <date> | str to-datetime -f <format>` | Parse a date ([format documentation](https://docs.rs/chrono/0.4.15/chrono/format/strftime/index.html)) |
| `sed` | `str find-replace` | Find and replace a pattern in a string |
| `grep <pattern>` | `where $it =~ <substring>` | Filter strings that contain the substring |
| `man <command>` | `help <command>` | Get the help for a given command |
| | `help commands` | List all available commands |
| | `help --find <string>` | Search for match in all available commands |
| `command1 && command2` | `command1; command2` | Run a command, and if it's successful run a second |
| `stat $(which git)` | `stat (which git).path` | Use command output as argument for other command |
| `echo $PATH` | `echo $nu.path` | See the current path |
| `<update ~/.bashrc>` | `config set path [<dir1> <dir2> ...]` | Update PATH permanently |
| `export PATH = $PATH:/usr/other/bin` | `pathvar add <path>` | Update PATH temporarily |
| `export` | `echo $nu.env` | List the current environment variables |
| `<update ~/.bashrc>` | `echo $nu.env | insert var value | config set_into env` | Update environment variables permanently |
| `FOO=BAR ./bin` | `FOO=BAR ./bin` | Update environment temporarily |
| `export FOO=BAR` | `let-env FOO = BAR` | Set environment variable for current session |
| `echo $FOO` | `echo $nu.env.FOO` | Use environment variables |
| `unset FOO` | `let-env FOO = $nothing` | Unset environment variable for current session |
| `alias s="git status -sb"` | `alias s = git status -sb` | Define an alias temporarily |
| `<update ~/.bashrc>` | `<update nu/config.toml>` | Add and edit alias permanently (for new shells), find path for the file with `config path` |
| `bash -c <commands>` | `nu -c <commands>` | Run a pipeline of commands (requires 0.9.1 or later) |
| `bash <script file>` | `nu <script file>` | Run a script file (requires 0.9.1 or later) |
| `\` | `<not yet possible>` | Line continuation is not yet supported. |

6 changes: 6 additions & 0 deletions old_book/command_reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Command Reference

<div v-for="command in $site.pages.filter(p => p.path.indexOf('/commands/') >= 0)">
<h1><code>{{ command.title }}</code></h1>
<Content :page-key="command.key"/>
</div>
27 changes: 27 additions & 0 deletions old_book/commands/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: How do I get started?
layout: command
---
Pick any command from the checklist and write a comment acknowledging you started work.

## Instructions for documenting a Nu command of your choosing

Name the file after the command, like so:

`command.md`

Example: If you want to add documentation for the Nu command `enter`, create a file named `enter.md`, write documentation, save it at `/docs/commands/[your_command_picked].md` as and create your pull request.

## What kind of documentation should I write?

Anything you want that you believe it *best* documents the command and the way you would like to see it. Here are some of our ideas of documentation we would *love* to see (feel free to add yours):

* Examples of using the command (max creativity welcomed!)
* Description of the command.
* Command usage.

## Anything else?

Of course! (These are drafts) so feel free to leave feedback and suggestions in the same file.

Happy Documenting.
36 changes: 36 additions & 0 deletions old_book/commands/alias.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: alias
layout: command
nu_version: 0.32
---

This command allows you to define shortcuts for other common commands. By default, they only apply to the current session. To persist them, add them to your config.

Syntax: `alias <name> = <body>`

The command expects two parameters:

* The name of the alias
* The body of the alias

## Examples

Define a custom `myecho` command as an alias:

```shell
> alias myecho = echo
> myecho "hello world"
hello world
```

The suggested help command works!

```shell
> myecho -h

Usage:
> myecho {flags}

flags:
-h, --help: Display this help message
```
29 changes: 29 additions & 0 deletions old_book/commands/all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: all
layout: command
nu_version: 0.32
---
Find if the table rows matches the condition.

## Usage
```shell
> all? <condition> {flags}
```

## Parameters
* `<condition>` the condition that must match

## Flags
* -h, --help: Display this help message

## Examples
Find if services are running
```shell
> echo [[status]; [UP] [UP]] | all? status == UP
```

Check that all values are even
```shell
> echo [2 4 6 8] | all? ($it mod 2) == 0
```

24 changes: 24 additions & 0 deletions old_book/commands/ansi-strip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: ansi strip
layout: command
nu_version: 0.32
---
strip ansi escape sequences from string

## Usage
```shell
> ansi strip ...args {flags}
```

## Parameters
* ...args: optionally, remove ansi sequences by column paths

## Flags
* -h, --help: Display this help message

## Examples
strip ansi escape sequences from string
```shell
> echo [(ansi gb) 'hello' (ansi reset)] | str collect | ansi strip
```

Loading