Starship

  • 特点:跨平台、轻量级,支持 Bash/Zsh/Fish,配置简单。
  • 需求在其他平台或者终端安装,参考官网:https://starship.rs/

必备字体,安装 Nerd Fonts(解决图标乱码问题)

  1. 安装 Nerd Fonts 以支持图标显示:https://www.nerdfonts.com/font-downloads

  2. 推荐安装Meslo Nerd Font

  3. 解压后右键字体文件 → “安装”

  4. 配置终端使用该字体

  • Windows Terminal:设置 → 配置文件 → PowerShell → 外观 → 字体选择 MesloLGM Nerd Font

  • VSCode 终端:设置中搜索 Terminal Font Family → 输入 'MesloLGM Nerd Font'。或者打开setting json文件添加

    "terminal.integrated.defaultProfile.windows": "PowerShell",
    "terminal.integrated.fontFamily": "'MesloLGM Nerd Font'"
    

1. 安装 Starship

winget install starship

2. 配置 PowerShell 启用 Starship

修改 PowerShell 配置文件

  1. 打开配置文件(如果不存在会自动创建):

    if (!(Test-Path $PROFILE)) { New-Item -Path $PROFILE -Type File -Force }
    notepad $PROFILE
    
  2. 在配置文件中添加以下内容

    Invoke-Expression (&starship init powershell)
    
  3. 保存文件并重启 PowerShell

3. 生成默认配置文件:

生成默认配置文件:

# 创建配置目录和文件
mkdir ~/.config
starship preset pastel-powerline > ~/.config/starship.toml

还有其他内置主题

starship preset pastel-powerline    # 柔和色系
starship preset pure-preset        # 极简风格
starship preset nerd-font-symbols  # 密集图标
starship preset tokyo-night

手动修改配置:

code ~/.config/starship.toml  # 用 VSCode 编辑配置文件

配置示例(显示时间、Git 分支、Python 版本):

[character]
success_symbol = "[➜](bold green)"
error_symbol = "[✗](bold red)"

[git_branch]
format = "on [🌱 $branch](bold purple)"

[time]
disabled = false
format = "🕒 [$time]($style)"

验证与重载

# 测试配置文件是否正确
starship explain

# 重载配置(修改后生效)
. $PROFILE

增强git提示功能

安装 posh-git:

在 PowerShell(管理员权限不是必须)执行:
Install-Module posh-git -Scope CurrentUser -Force

更新(以后):
Update-Module posh-git

卸载(参考):
Uninstall-Module posh-git

在 Profile 中加载(并与 Starship 共存):

编辑个人配置:
notepad PROFILE 如果提示路径不存在,先: New-Item -ItemType File -Path PROFILE -Force | Out-Null

最简正确的 Profile 示例:

Import-Module posh-git
Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView  # 或 InlineView
Set-PSReadLineKeyHandler -Key Tab -Function Complete  # 或 MenuComplete
Invoke-Expression (& starship init powershell)