Nu shell Oh My Posh

给 Nu shell 配置上 Oh My Posh,完成后效果如下。

nu-ohmyposh

之前我已经给 powershell 配置好 ohmyposh 了,现在感觉还是 nu shell 比较好用,所以也来折腾一下。

官方文档:Change your prompt | Oh My Posh

有这些 shell 可以选择:

  • bash
  • cmd
  • elvish
  • fish
  • nu
  • powershell
  • tcsh
  • xonsh
  • zsh

点击中间的 nu 可以看到说明。

简单来说,就是修改 nushell 的两个配置文件就好。它们在 ~\AppData\Roaming\nushell 里面。

添加

oh-my-posh init nu

env.nu 里面,我直接写在第四行的位置。

# Nushell Environment Config File
alias ll = ls -l

oh-my-posh init nu

然后再到 config.nu 的最后,添加这一行。

source ~/.oh-my-posh.nu

它会生成 ~/.oh-my-posh.nu ,也就是在用户目录下。打开后里面是这些内容。

export-env {
let-env POWERLINE_COMMAND = 'oh-my-posh'
let-env POSH_THEME = ''
let-env PROMPT_INDICATOR = ""
let-env POSH_PID = (random uuid)
# By default displays the right prompt on the first line
# making it annoying when you have a multiline prompt
# making the behavior different compared to other shells
let-env PROMPT_COMMAND_RIGHT = {''}
let-env POSH_SHELL_VERSION = (version | get version)

# PROMPTS
let-env PROMPT_MULTILINE_INDICATOR = (^"C:/Users/nucx/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe" print secondary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)")

let-env PROMPT_COMMAND = {
# We have to do this because the initial value of `$env.CMD_DURATION_MS` is always `0823`,
# which is an official setting.
# See https://github.com/nushell/nushell/discussions/6402#discussioncomment-3466687.
let cmd_duration = if $env.CMD_DURATION_MS == "0823" { 0 } else { $env.CMD_DURATION_MS }

# hack to set the cursor line to 1 when the user clears the screen
# this obviously isn't bulletproof, but it's a start
let clear = (history | last 1 | get 0.command) == "clear"

let width = ((term size).columns | into string)
^"C:/Users/nucx/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe" print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=($cmd_duration)" $"--error=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" $"--cleared=($clear)"
}
}

if "false" == "true" {
echo ""
}