ter

macOS 终端

Windows 终端

查看 PowerShell 当前版本,在 PowerShell 中运行以下任一命令:

$PSVersionTable             # 显示包含版本、编辑模式等详细列表
$PSVersionTable.PSVersion	# 直接返回主版本号,例如 Major、Minor、Build 号

安装 PowerShell 7,推荐使用 Winget,在现有的 PowerShell 运营以下命令:

winget install --id Microsoft.PowerShell --source winget
winget install --id Microsoft.PowerShell.Preview --source winget # 安装预览版

ℹ️Install PowerShell on Windows - PowerShell | Microsoft Learn

PowerShell 7 的可执行文件名为 pwsh.exe,而 Windows PowerShell 5 是 powerselle.exe

PowerShell 7 默认安装在 C:\Program Files\PowerShell\7\ 目录下。

Oh My Zsh

参考资料

下载的第三方主题可以放在 ~/.oh-my-zsh/custom/themes,我安装了 powerlevel10k 主题,可以用 p10k configure 来引导设置。

Oh My Posh

Home | Oh My Posh

安装(Windows)

  1. 运行 winget install JanDeDobbeleer.OhMyPosh --source winget 进行安装。
  2. 运行 oh-my-posh font install 安装字体,推荐 Meslo,如果不能正常安装,就手动下载字体:
    • Nerd Fonts,选择 MesloLG Nerd Font 下载。
    • 下载之后解压,安装所有 .ttf 文件。
  3. 设置主题,在 Microsoft.PowerShell_profile.ps1 文件 输入 oh-my-posh init pwsh --config "F:\Documents\MyPoshThemes\M365Princess.omp.json" | Invoke-Expression,运行 .$PROFILE,主题就设置好了。
    • 当前用户的 Profile 的路径在 $HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
    • 不能用官方提供的设置方法来设置主题,我需要把主题从安装路径手动复制到我想存放的地方,比如 F:\Documents\MyPoshThemes

以下为旧内容:

  • 我的 PowerShell 的配置文件位置为:E:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 可以用 $PROFILE 命令查看配置文件位置
  • 为 Windows 终端安装使用 oh-my-posh
    1. 打开 PowerShell 运行以下命令安装(也可以在微软商店安装):
      winget install JanDeDobbeleer.OhMyPosh -s winget
    2. 如果重启终端 oh-my-posh 不被识别为命令,此时可以再次运行安装程序,或将它手动添加到 PATH 中:
      $env:Path += ";C:\Users\user\AppData\Local\Programs\oh-my-posh\bin" # 注意将user修改为自己的
      # 我目前的oh-my-posh路径为:C:\Users\wangh\AppData\Local\Programs\oh-my-posh
      
    3. 可以用以下命令进行更新:
      winget upgrade JanDeDobbeleer.OhMyPosh -s winget
      
    4. 将 PowerShell 的 profile 增加一行,设置主题:
      C:\\Users\\wangh\\AppData\\Local\\Programs\\oh-my-posh\\bin\\oh-my-posh.exe init pwsh --config $env:POSH_THEMES_PATH\sorin.omp.json | Invoke-Expression # 可以通过修改POSH_THEMES_PATH后面的json来修改主题
      

一些常用命令