Windows 的 Nushell 配置与 VSCode 集成(不说废话)

Windows 的 Nushell 配置与 VSCode 集成(不说废话)

Windows 的 Nushell 配置与 VSCode 集成(不说废话)在 Windows 平台上,厌倦了 pwsh 动辄一两秒的启动时间?苦于没有可爱的 fish?来试试 Nushell 吧!Rust 万岁!

Warning

Nushell 在 Windows 可能会遇到各种奇怪的问题,虽然启动快,但请谨慎使用!

Nushell 安装按照官方指示即可,此处不赘述。

仓库:https://github.com/nushell/nushell文档:https://www.nushell.sh/awesome:https://github.com/nushell/awesome-nu官方首选 winget,但 winget 版本会稍旧。本文写作时,Nushell 0.96.0 刚发布两天,winget 最新只有 0.95.0。也可以使用 scoop。

使用 winget 时,由于是从 GitHub 下载,速度可能会特别慢。遇到这种情况可以直接从 release 处下载,然后把 .msi 文件复制到 %TEMP%\WinGet 下对应的目录里,重新执行 winget install nushell,即可读取缓存立即进入安装。 建议管理员模式下安装,避免安装失败。

安装成功后,重启终端,执行 nu 即可进入。

Starship 安装美化 Nushell。

仓库:https://github.com/starship/starship文档:https://starship.rs/按照上面指示即可,包括本体、Nerd Font、与终端集成。完成后可能需要重启,不然 Nerd 字体无法正常显示。

可采用预设主题,见 https://starship.rs/presets/。

VSCode 集成在 settings.json 里添加如下内容:

{

"terminal.integrated.profiles.windows": {

"Nushell": {

"path": "C:/Program Files/nu/bin/nu.exe"

}

},

"terminal.integrated.defaultProfile.windows": "Nushell",

"terminal.integrated.fontFamily": "FiraCode Nerd Font Mono" // Change to your Nerd Font name

}其中 terminal.integrated.profiles.windows 字段应该已有其他终端配置项,Nushell 的安装路径可通过 which nu 获取。

这样把 Nushell 作为默认终端,并启用 Nerd Font 以正常显示 Starship。

使用相关快捷键:https://www.nushell.sh/book/line_editor.html 和大部分 shell 基本一致。区别于 pwsh,无法通过按 F2 切换历史提示是 inline 还是 list。

自动补全 是一个 menu,按 Tab 触发。

历史补全 也是一个 menu,需要按 Ctrl+R 开启,不像 pwsh 永久,它是暂时的。感觉没 pwsh 的好用。

历史补全示例,似乎不准自动补全见 awesome-nu 的 Custom Completions

官方提供了大量的补全脚本:https://github.com/nushell/nu_scripts/tree/main/custom-completions

但这样使用比较麻烦,所以我们使用 carapace。

官网:https://carapace.sh/仓库:https://github.com/carapace-sh/carapace使用文档:https://carapace-sh.github.io/carapace-bin/carapace-bin.html直接按照 carapace 的指示做就行了,不需要修改 config.nu 里自动补全相关设置。 配置文件路径可通过 $nu.config-path 获取,不一定在指南里的 .config 下。

然后重开终端就可以体验自动补全了。下面检查一下。

自动补全相关配置补全的原理是调用一个命令:

调用 carapace 获取补全结果自动补全使用感觉挺卡的,不如内联补全实用。

git 补全示例一些样式可以在 https://carapace-sh.github.io/carapace-bin/style.html 里调。

顺带一提,pwsh 的自动补全可以类似地集成。配置文件路径以 MS 官方为准

重要配置这部分涉及体验优化。 笔者暂时没有在官网找到完整配置项的解释,但好在 config.nu 里有详细注释可帮助配置。

历史这里需要解决一个头疼的问题:为什么我的历史记录会在多个打开的终端间共享? 这个很讨厌,因为会经常在同一个终端往上切换历史,如果历史串了不仅引入无关项,还容易导致误操作。 甚至 GPT 都不知道如何解决这个问题,但好在它提示我看 history 相关配置。

❯ $env.config.history

╭───────────────┬───────────╮

│ max_size │ 100000 │

│ sync_on_enter │ true │

│ file_format │ plaintext │

│ isolation │ false │

╰───────────────┴───────────╯具体配置项:

{

max_size: 100_000 # Session has to be reloaded for this to take effect

sync_on_enter: true # Enable to share history between multiple sessions, else you have to close the session to write history to file

file_format: "plaintext" # "sqlite" or "plaintext"

isolation: false # only available with sqlite file_format. true enables history isolation, false disables it. true will allow the history to be isolated to the current session using up/down arrows. false will allow the history to be shared across all sessions.

}为最大程度地隔离,把两个 bool 都置反。

$env.config.history.sync_on_enter = false

$env.config.history.isolation = true但实际上,如果 sync_on_enter 设为 false,就会导致直接就不写历史了,所以还是保留 true 吧。

$env.config.history.isolation = true时间显示配置项为 datetime_format,默认为空。

默认是显示的,但安装 starship 后被覆盖了,默认是不显示的。

相关问题路径Warning

这是一个致命的问题,导致部分运行代码的插件无法正常使用!

在 VSCode 里运行 python 脚本或其他,会遇到 can't open file 之类的问题。Nushell 并非不支持反斜杠,而是因为路径被引号包住(路径里有空格时需要这样做),这样里面的路径反斜杠就成了转义符,使得路径错误。

如果是自己来跑程序,可以把双引号改成单引号,这样就不会视为转义。但这命令是插件生成的…… 暂未找到解决方法。

相关推荐

气候变化另类危机——超大冰雹灾害
365bet亚洲平台

气候变化另类危机——超大冰雹灾害

📅 01-15 👍 425
梅花天使创投品牌介绍
Bet体育365提款要多久

梅花天使创投品牌介绍

📅 06-29 👍 414
新笑傲江湖哪个职业厉害
Bet体育365提款要多久

新笑傲江湖哪个职业厉害

📅 02-01 👍 212