Skip to content

Commit d283b10

Browse files
support extracting nu code snippets into standalone .nu files for better downstream trackability (#2162)
1 parent 8d810c4 commit d283b10

8 files changed

Lines changed: 103 additions & 39 deletions

File tree

.vuepress/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { shikiPlugin } from '@vuepress/plugin-shiki';
66
import { defaultTheme } from '@vuepress/theme-default';
77
import { sitemapPlugin } from '@vuepress/plugin-sitemap';
88
import { docsearchPlugin } from '@vuepress/plugin-docsearch';
9+
import { markdownIncludePlugin } from '@vuepress/plugin-markdown-include';
910

1011
import {
1112
navbarDe,
@@ -220,6 +221,7 @@ export default defineUserConfig({
220221
plugins: [
221222
// Note: gitPlugin, backToTopPlugin, mediumZoomPlugin, and copyCodePlugin
222223
// are already included in defaultTheme, so we don't need to add them here
224+
markdownIncludePlugin({}),
223225
shikiPlugin({
224226
themes: {
225227
light: 'dark-plus',

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ ls | where type == file | sort-by -r size | first 5
7070

7171
The preferred form for consistency is `` ```nu ``.
7272

73+
If the snippet is a reusable block that readers might want to source directly and track over time, save it as a sibling `.nu` file and include it inside the fence with `<!-- @include: ./example.nu -->` (see `cookbook/direnv.md` for an example).
74+
7375
## Translation Guide
7476

7577
Follow the steps above for each group of translations.

cookbook/direnv.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,7 @@ The direnv configuration below requires Nushell 0.104 or later.
2727
:::
2828

2929
```nu
30-
use std/config *
31-
32-
# Initialize the PWD hook as an empty list if it doesn't exist
33-
$env.config.hooks.env_change.PWD = $env.config.hooks.env_change.PWD? | default []
34-
35-
$env.config.hooks.env_change.PWD ++= [{||
36-
if (which direnv | is-empty) {
37-
# If direnv isn't installed, do nothing
38-
return
39-
}
40-
41-
direnv export json | from json | default {} | load-env
42-
# If direnv changes the PATH, it will become a string and we need to re-convert it to a list
43-
$env.PATH = do (env-conversions).path.from_string $env.PATH
44-
}]
30+
<!-- @include: ./direnv.nu -->
4531
```
4632

4733
As with other configuration changes, this can be made permanent by adding it to your startup [configuration](/book/configuration.md).

cookbook/direnv.nu

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std/config *
2+
3+
# Initialize the PWD hook as an empty list if it doesn't exist
4+
$env.config.hooks.env_change.PWD = $env.config.hooks.env_change.PWD? | default []
5+
6+
$env.config.hooks.env_change.PWD ++= [{||
7+
if (which direnv | is-empty) {
8+
# If direnv isn't installed, do nothing
9+
return
10+
}
11+
12+
direnv export json | from json | default {} | load-env
13+
# If direnv changes the PATH, it will become a string and we need to re-convert it to a list
14+
$env.PATH = do (env-conversions).path.from_string $env.PATH
15+
}]

cookbook/ssh_agent.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,7 @@ See the workarounds.
2626
You can work around this behavior by checking if a ssh-agent is already running on your user, and start one if none is:
2727

2828
```nu
29-
do --env {
30-
let ssh_agent_file = (
31-
$nu.temp-dir | path join $"ssh-agent-(whoami).nuon"
32-
)
33-
34-
if ($ssh_agent_file | path exists) {
35-
let ssh_agent_env = open ($ssh_agent_file)
36-
if ($"/proc/($ssh_agent_env.SSH_AGENT_PID)" | path exists) {
37-
load-env $ssh_agent_env
38-
return
39-
} else {
40-
rm $ssh_agent_file
41-
}
42-
}
43-
44-
let ssh_agent_env = ^ssh-agent -c
45-
| lines
46-
| first 2
47-
| parse "setenv {name} {value};"
48-
| transpose --header-row
49-
| into record
50-
load-env $ssh_agent_env
51-
$ssh_agent_env | save --force $ssh_agent_file
52-
}
29+
<!-- @include: ./ssh_agent_workaround.nu -->
5330
```
5431

5532
### [Keychain](https://www.funtoo.org/Funtoo:Keychain)

cookbook/ssh_agent_workaround.nu

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
do --env {
2+
let ssh_agent_file = (
3+
$nu.temp-dir | path join $"ssh-agent-(whoami).nuon"
4+
)
5+
6+
if ($ssh_agent_file | path exists) {
7+
let ssh_agent_env = open ($ssh_agent_file)
8+
if ($"/proc/($ssh_agent_env.SSH_AGENT_PID)" | path exists) {
9+
load-env $ssh_agent_env
10+
return
11+
} else {
12+
rm $ssh_agent_file
13+
}
14+
}
15+
16+
let ssh_agent_env = ^ssh-agent -c
17+
| lines
18+
| first 2
19+
| parse "setenv {name} {value};"
20+
| transpose --header-row
21+
| into record
22+
load-env $ssh_agent_env
23+
$ssh_agent_env | save --force $ssh_agent_file
24+
}

package-lock.json

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@vuepress/bundler-vite": "2.0.0-rc.26",
1818
"@vuepress/plugin-docsearch": "2.0.0-rc.118",
1919
"@vuepress/plugin-feed": "2.0.0-rc.118",
20+
"@vuepress/plugin-markdown-include": "2.0.0-rc.118",
2021
"@vuepress/plugin-shiki": "2.0.0-rc.118",
2122
"@vuepress/plugin-sitemap": "2.0.0-rc.118",
2223
"@vuepress/theme-default": "2.0.0-rc.118",

0 commit comments

Comments
 (0)