Skip to content

Commit 70f861d

Browse files
authored
Update/Rename shells-in-shells chapter (#1653)
1 parent efb0a7a commit 70f861d

File tree

7 files changed

+144
-59
lines changed

7 files changed

+144
-59
lines changed

.vuepress/configs/sidebar/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const sidebarEn: SidebarConfig = {
7676
'/book/stdout_stderr_exit_codes.md',
7777
'/book/escaping.md',
7878
'/book/3rdpartyprompts.md',
79-
'/book/shells_in_shells.md',
79+
'/book/directory_stack.md',
8080
'/book/line_editor.md',
8181
'/book/custom_completions.md',
8282
'/book/externs.md',

book/directory_stack.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Directory Stack
2+
3+
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.
4+
5+
::: note
6+
In Nushell, the "stack" is represented as a `list`, but the overall functionality is similar to that of other shells.
7+
:::
8+
9+
[[toc]]
10+
11+
## `dirs` Module and Commands
12+
13+
To use the `dirs` command and its subcommands, first import the module using:
14+
15+
```nu
16+
use std/dirs
17+
```
18+
19+
::: tip
20+
To make the feature available whenever you start Nushell, add the above command to your [startup configuration](./configuration.md).
21+
:::
22+
23+
This makes several new commands available:
24+
25+
| Command | Description |
26+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
27+
| `dirs` | Lists the directories on the stack |
28+
| `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. |
29+
| `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. |
30+
| `dirs goto` | Jumps to directory by using its index in the list |
31+
| `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. |
32+
| `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. |
33+
34+
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.
35+
36+
```nu
37+
cd ~
38+
use std/dirs
39+
dirs
40+
# => ╭───┬────────┬─────────────────────────────────╮
41+
# => │ # │ active │ path │
42+
# => ├───┼────────┼─────────────────────────────────┤
43+
# => │ 0 │ true │ /home/myuser │
44+
# => ╰───┴────────┴─────────────────────────────────╯
45+
46+
cd ~/src/repo/nushell
47+
dirs
48+
# => ╭───┬────────┬─────────────────────────────────╮
49+
# => │ # │ active │ path │
50+
# => ├───┼────────┼─────────────────────────────────┤
51+
# => │ 0 │ true │ /home/myuser/repo/nushell │
52+
# => ╰───┴────────┴─────────────────────────────────╯
53+
54+
```
55+
56+
Notice that `cd` only changes the Active directory.
57+
58+
To _add_ the current directory to the list, change to a new active directory using the `dirs add` command:
59+
60+
```nu
61+
dirs add ../reedline
62+
dirs
63+
# => ╭───┬────────┬──────────────────────────────────╮
64+
# => │ # │ active │ path │
65+
# => ├───┼────────┼──────────────────────────────────┤
66+
# => │ 0 │ false │ /home/myuser/src/repo/nushell │
67+
# => │ 1 │ true │ /home/myuser/src/repo/reedline │
68+
# => ╰───┴────────┴──────────────────────────────────╯
69+
```
70+
71+
Let's go ahead and add a few more commonly used directories to the list:
72+
73+
```nu
74+
dirs add ../nu_scripts
75+
dirs add ~
76+
dirs
77+
# => ╭───┬────────┬────────────────────────────────────╮
78+
# => │ # │ active │ path │
79+
# => ├───┼────────┼────────────────────────────────────┤
80+
# => │ 0 │ false │ /home/myuser/src/repo/nushell │
81+
# => │ 1 │ false │ /home/myuser/src/repo/reedline │
82+
# => │ 2 │ false │ /home/myuser/src/repo/nu_scripts │
83+
# => │ 3 │ true │ /home/myuser │
84+
# => ╰───┴────────┴────────────────────────────────────╯
85+
```
86+
87+
We can now switch between them easily using `dirs next`, `dirs prev` or `dirs goto`:
88+
89+
```nu
90+
dirs next
91+
# Active was 3, is now 0
92+
pwd
93+
# => /home/myuser/src/repo/nushell
94+
dirs goto 2
95+
# => /home/myuser/src/repo/nu_scripts
96+
```
97+
98+
When you have finished your work in a directory, you can drop it from the list using:
99+
100+
```nu
101+
dirs drop
102+
dirs
103+
# => ╭───┬────────┬──────────────────────────────────╮
104+
# => │ # │ active │ path │
105+
# => ├───┼────────┼──────────────────────────────────┤
106+
# => │ 0 │ false │ /home/myuser/src/repo/nushell │
107+
# => │ 1 │ true │ /home/myuser/src/repo/reedline │
108+
# => │ 2 │ false │ /home/myuser │
109+
# => ╰───┴────────┴──────────────────────────────────╯
110+
```
111+
112+
When we drop `nu_scripts` from the list, the previous directory (`reedline`) becomes active.
113+
114+
## `shells` Aliases
115+
116+
Some users may prefer to think of this feature as multiple "shells within shells", where each has its own directory.
117+
118+
The Standard Library provides a set of aliases that can be used in place of the `dirs` commands above.
119+
120+
Import them using:
121+
122+
```nu
123+
use std/dirs shell-aliases *
124+
```
125+
126+
The built-in aliases are:
127+
128+
| Alias | Description |
129+
| -------- | -------------------------------------------------------- |
130+
| `shells` | in place of `dirs` to list current "shells"/directories. |
131+
| `enter` | in place of `dirs add` to enter a new "shell"/dir. |
132+
| `dexit` | in place of `dirs drop` to exit a "shell"/dir. |
133+
| `g` | as an alias for `dirs goto`. |
134+
| `n` | for `dirs next` |
135+
| `p` | for `dirs prev` |
136+
137+
Of course, you can also define your own aliases if desired.

book/nu_as_a_shell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This brings in some additional design considerations so please refer to the link
1414

1515
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.
1616

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

1919
Nushell also has its own line editor [Reedline](line_editor.md).
2020
With Nushell's config, it is possible to configure some of the Reedline's features, such as the prompt, keybindings, history, or menus.

book/shells_in_shells.md

Lines changed: 0 additions & 52 deletions
This file was deleted.

book/table_of_contents.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- [Scripts](scripts.md) - Creating your own scripts
2525
- [Metadata](metadata.md) - An explanation of Nu's metadata system
2626
- [Creating your own errors](creating_errors.md) - Creating your own error messages
27-
- [Shells](shells_in_shells.md) - Working with multiple locations
27+
- [Directory Stack](directory_stack.md) - Working with multiple locations
2828
- [Escaping commands](escaping.md) - Escaping to native commands of the same name
2929
- [Plugins](plugins.md) - Enhancing Nushell with more features using plugins
3030
- [Parallelism](parallelism.md) - Running your code in parallel

de/book/nu_as_a_shell.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Dies bringt einige zusätzliche Design Überlegungen mit sich, welche in den ver
1616
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.
1717
Sowie wie ein [Drittanbieter Prompt](3rdpartyprompts.md) zur Zusammenarbeit mit Nushell bewegt werden kann.
1818

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

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

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

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

3030
Schliesslich erklärt [Hooks](hooks.md) wie Fragmente von Nushell Code beim Auftreten gewisser Ereignisse ausgeführt werden kann.

zh-CN/book/shells_in_shells.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
3 │ Gemfile.lock │ File │ 6.9 KB │ 2 hours ago
1919
```
2020

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

2323
```nu
2424
/home/sophia/Source/book(main)> shells
@@ -32,7 +32,7 @@
3232
3333
```
3434

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

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

0 commit comments

Comments
 (0)