Win10 命令行美化笔记

win10自带的Power Shell进行美化,目标:

  • 不需要单独启动(Fluent Terminal等),能与原生的Power Shell完美契合。
  • 比较美观,符合主流审美,高亮、提示功能友好。原生的Power Shell在处理命令行的参数时字体颜色偏暗。

主要工具

  • Scoop:windows 系统中的包管理工具,可用于下载 ConEmu
  • ConEmu:命令行客户端,可设置为替代原生的Power Shell,符合第一点目标。
  • oh-my-poshConEmuPower Shell提示的主题功能。
  • Power Line 字体:用于替换原生命令行的字体,并增加扩充字体图标库。
  • Git:用于从码云下载 Power Line 字体

具体操作

  1. 安装 Scoop:

    Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
  2. 安装 ConEmu:

    scoop install ConEmu
  3. 安装以及配置 oh-my-push:

    Install-Module posh-git -Scope CurrentUser
    Install-Module oh-my-posh -Scope CurrentUser

    中途会要求确认:

    • 安装导入 NuGety
    • PSGallery安装模块:a

    初始化以及配置

    # 默认设置
    Set-Prompt
    # 设置配色主题
    Set-Theme Agnoster

    修改PowerShell的配置文件,让每一次启动时自动加载一些配置:

    if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force } notepad $PROFILE

    在打开的配置文件中添加:

    Import-Module posh-git
    Import-Module oh-my-posh
    Set-Theme Agnoster(这里可以是任意配色主题)

    其他相关配置以及所有可用主题可参考 https://github.com/JanDeDobbeleer/oh-my-posh#configuration

  4. 安装 Power Line 字体:

    git clone https://github.com/powerline/fonts.git --depth=1
    cd fonts
    ./install.ps1

    安装完后,可以删了这个文件夹。

  5. 配置 ConEmu:

    打开 ConEmu,在 标题栏-右键-settings 进入设置界面。

    • 修改语言:通用-Interface language 选择 zh: 简体中文
    • 修改字体:通用-字体-控制台主要字体 选择 Meslo LG M Regular for Powerline Nerd Font
    • 修改字符集:通用-字体-Unicode 范围 选择 Dashes and Borders: 2013-2015;2500-25C4;
    • 修改默认shell:启动-任务-预定义的任务-{Shells::PowerShell(Admin)} 右侧勾选 默认shell
    • 替换默认 PowerShell :集成-默认终端 右侧勾选 强制使用ConEmu作为控制台的默认终端在系统启动时注册
    • 修改主题配色: 通用-Choose color scheme 选择 Babun
    • 设置多窗口运行:通用-外观取消勾选 单例模式, 标题栏设置不隐藏,在 通用-标签栏 中设置 不要显示,在 功能特性-状态栏 取消勾选 显示状态栏

    以上配置文件信息(保存在xml文件中,可以直接导入):Github:ConEmu-settings

相关参考