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
2 changes: 1 addition & 1 deletion .vuepress/configs/sidebar/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const sidebarEn: SidebarConfig = {
'/book/stdout_stderr_exit_codes.md',
'/book/escaping.md',
'/book/3rdpartyprompts.md',
'/book/shells_in_shells.md',
'/book/directory_stack.md',
'/book/line_editor.md',
'/book/custom_completions.md',
'/book/externs.md',
Expand Down
137 changes: 137 additions & 0 deletions book/directory_stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Directory Stack

Like some other shells, Nushell provides a Directory Stack feature for easily switching between multiple directories. In Nushell, this feature is part of the [Standard Library](./standard_library.md) and can be accessed in several ways.

::: note
In Nushell, the "stack" is represented as a `list`, but the overall functionality is similar to that of other shells.
:::

[[toc]]

## `dirs` Module and Commands

To use the `dirs` command and its subcommands, first import the module using:

```nu
use std/dirs
```

::: tip
To make the feature available whenever you start Nushell, add the above command to your [startup configuration](./configuration.md).
:::

This makes several new commands available:

| Command | Description |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `dirs` | Lists the directories on the stack |
| `dirs add` | Adds one or more directories to the list. The first directory listed becomes the new active directory. Similar to the `pushd` command in some other shells. |
| `dirs drop` | Drops the current directory from the list. The previous directory in the list becomes the new active directory. Similar to the `popd` command in some other shells. |
| `dirs goto` | Jumps to directory by using its index in the list |
| `dirs next` | Makes the next directory on the list the active directory. If the current active directory is the last in the list, then cycle to the start of the list. |
| `dirs prev` | Makes the previous directory on the list the active directory. If the current active directory is the first in the list, then cycle to the end of the list. |

When we start using `dirs`, there is only one directory in the list, the active one. You can, as always, change this directory using the `cd` command.

```nu
cd ~
use std/dirs
dirs
# => ╭───┬────────┬─────────────────────────────────╮
# => │ # │ active │ path │
# => ├───┼────────┼─────────────────────────────────┤
# => │ 0 │ true │ /home/myuser │
# => ╰───┴────────┴─────────────────────────────────╯

cd ~/src/repo/nushell
dirs
# => ╭───┬────────┬─────────────────────────────────╮
# => │ # │ active │ path │
# => ├───┼────────┼─────────────────────────────────┤
# => │ 0 │ true │ /home/myuser/repo/nushell │
# => ╰───┴────────┴─────────────────────────────────╯

```

Notice that `cd` only changes the Active directory.

To _add_ the current directory to the list, change to a new active directory using the `dirs add` command:

```nu
dirs add ../reedline
dirs
# => ╭───┬────────┬──────────────────────────────────╮
# => │ # │ active │ path │
# => ├───┼────────┼──────────────────────────────────┤
# => │ 0 │ false │ /home/myuser/src/repo/nushell │
# => │ 1 │ true │ /home/myuser/src/repo/reedline │
# => ╰───┴────────┴──────────────────────────────────╯
```

Let's go ahead and add a few more commonly used directories to the list:

```nu
dirs add ../nu_scripts
dirs add ~
dirs
# => ╭───┬────────┬────────────────────────────────────╮
# => │ # │ active │ path │
# => ├───┼────────┼────────────────────────────────────┤
# => │ 0 │ false │ /home/myuser/src/repo/nushell │
# => │ 1 │ false │ /home/myuser/src/repo/reedline │
# => │ 2 │ false │ /home/myuser/src/repo/nu_scripts │
# => │ 3 │ true │ /home/myuser │
# => ╰───┴────────┴────────────────────────────────────╯
```

We can now switch between them easily using `dirs next`, `dirs prev` or `dirs goto`:

```nu
dirs next
# Active was 3, is now 0
pwd
# => /home/myuser/src/repo/nushell
dirs goto 2
# => /home/myuser/src/repo/nu_scripts
```

When you have finished your work in a directory, you can drop it from the list using:

```nu
dirs drop
dirs
# => ╭───┬────────┬──────────────────────────────────╮
# => │ # │ active │ path │
# => ├───┼────────┼──────────────────────────────────┤
# => │ 0 │ false │ /home/myuser/src/repo/nushell │
# => │ 1 │ true │ /home/myuser/src/repo/reedline │
# => │ 2 │ false │ /home/myuser │
# => ╰───┴────────┴──────────────────────────────────╯
```

When we drop `nu_scripts` from the list, the previous directory (`reedline`) becomes active.

## `shells` Aliases

Some users may prefer to think of this feature as multiple "shells within shells", where each has its own directory.

The Standard Library provides a set of aliases that can be used in place of the `dirs` commands above.

Import them using:

```nu
use std/dirs shell-aliases *
```

The built-in aliases are:

| Alias | Description |
| -------- | -------------------------------------------------------- |
| `shells` | in place of `dirs` to list current "shells"/directories. |
| `enter` | in place of `dirs add` to enter a new "shell"/dir. |
| `dexit` | in place of `dirs drop` to exit a "shell"/dir. |
| `g` | as an alias for `dirs goto`. |
| `n` | for `dirs next` |
| `p` | for `dirs prev` |

Of course, you can also define your own aliases if desired.
2 changes: 1 addition & 1 deletion book/nu_as_a_shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This brings in some additional design considerations so please refer to the link

The other sections explain how to work with [stdout, stderr and exit codes](stdout_stderr_exit_codes.md), how to [escape a command call to the external command call](escaping.md), and how to [configure 3rd party prompts](3rdpartyprompts.md) to work with Nushell.

An interesting feature of Nushell is [shells](shells_in_shells.md) which let you work in multiple directories simultaneously.
An interesting feature of Nushell is the [Directory Stack](directory_stack.md) which let you work in multiple directories simultaneously.

Nushell also has its own line editor [Reedline](line_editor.md).
With Nushell's config, it is possible to configure some of the Reedline's features, such as the prompt, keybindings, history, or menus.
Expand Down
52 changes: 0 additions & 52 deletions book/shells_in_shells.md

This file was deleted.

2 changes: 1 addition & 1 deletion book/table_of_contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- [Scripts](scripts.md) - Creating your own scripts
- [Metadata](metadata.md) - An explanation of Nu's metadata system
- [Creating your own errors](creating_errors.md) - Creating your own error messages
- [Shells](shells_in_shells.md) - Working with multiple locations
- [Directory Stack](directory_stack.md) - Working with multiple locations
- [Escaping commands](escaping.md) - Escaping to native commands of the same name
- [Plugins](plugins.md) - Enhancing Nushell with more features using plugins
- [Parallelism](parallelism.md) - Running your code in parallel
Expand Down
4 changes: 2 additions & 2 deletions de/book/nu_as_a_shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Dies bringt einige zusätzliche Design Überlegungen mit sich, welche in den ver
Die anderen Kapitel erklären wie mit [stdout, stderr und exit codes (EN)](/book/stdout_stderr_exit_codes.md) gearbeitet werden kann, oder wie ein [Befehl zu einem externer Befehl "escaped"](escaping.md) werden kann.
Sowie wie ein [Drittanbieter Prompt](3rdpartyprompts.md) zur Zusammenarbeit mit Nushell bewegt werden kann.

Ein interessantes Merkmal von Nushell ist [Shell in Shells (EN)](/book/shells_in_shells.md) welches erlaubt in mehreren Verzeichnissen gleichzeitig zu arbeiten.
Ein interessantes Merkmal von Nushell ist [Shell in Shells (EN)](/book/directory_stack.md) welches erlaubt in mehreren Verzeichnissen gleichzeitig zu arbeiten.

Nushell hat auch seinen eigenen Zeilen Editor [Reedline (EN)](/book/line_editor.md).
In Nushells Konfiguration ist es möglich einige Merkmale von Reedline wie Prompt, Tastenkombinationen, History oder Menus einzustellen.
Expand All @@ -25,6 +25,6 @@ Es ist auch möglich, eigene [Signaturen für externe Befehle (EN)](/book/extern

[Farben und Themen in Nu](coloring_and_theming.md)) geht ins Detail zum Thema, wie Nushells Aussehen konfiguriert werden kann.

Sind einige Befehle geplant , die im Hintergrund ablaufen sollen, so kann darüber in [Hintergrund Tasks in Nu](background_task.md) nachgelesen werden.
Sind einige Befehle geplant , die im Hintergrund ablaufen sollen, so kann darüber in [Hintergrund Tasks in Nu](background_task.md) nachgelesen werden.

Schliesslich erklärt [Hooks](hooks.md) wie Fragmente von Nushell Code beim Auftreten gewisser Ereignisse ausgeführt werden kann.
4 changes: 2 additions & 2 deletions zh-CN/book/shells_in_shells.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
3 │ Gemfile.lock │ File │ 6.9 KB │ 2 hours ago
```

进入(`enter`)类似于改变目录(正如我们在`cd`命令中看到的那样)。这允许你跳入一个目录,在其中工作。我们现在是在两个目录中,而不是改变目录。为了更清楚地看到这一点,我们可以使用[`shells`](/commands/docs/shells.md)命令来列出我们当前的活动目录:
进入(`enter`)类似于改变目录(正如我们在`cd`命令中看到的那样)。这允许你跳入一个目录,在其中工作。我们现在是在两个目录中,而不是改变目录。为了更清楚地看到这一点,我们可以使用`shells`命令来列出我们当前的活动目录:

```nu
/home/sophia/Source/book(main)> shells
Expand All @@ -32,7 +32,7 @@

```

[`shells`](/commands/docs/shells.md)命令显示目前有三个 Shells 处于活动状态:我们最初的 "nushell" 源目录和现在的新 "book" 目录。
`shells`命令显示目前有三个 Shells 处于活动状态:我们最初的 "nushell" 源目录和现在的新 "book" 目录。

我们可以用 `n`, `p` 和 `g` 的快捷命令在这些 Shell 之间跳转,这是 "next"、"previous" 和 "go" 的缩写:

Expand Down