Windows Terminal + Powershell7,这才是终端该有样子。

斌仔 分类:
文章字数 773 字 阅读时间 6 分钟
🤖 由 ChatGPT 生成的文章摘要
此内容根据文章生成,并经过人工审核,仅用于文章内容的解释与总结

阿斌在 Mac 上使用的终端是 iTerm2+oh my zsh,这两者搭配再加上一些插件可以实现一些命令的自动补全的功能。

但在 Windows 自带的 powershell 、cmd 都没有这些功能,之前使用过 cmder,用着也还不错,但是仍感感觉少点啥。

再搜索发现有人使用 Windows Terminal + Powershell7 不仅能自动补全还能自定义主题,找着折腾的那味了。

既然能满足需求了,那就开整吧。

Powershell7
Powershell7

软件安装

  1. 在 Microsoft Store 搜索:Windows Terminal 并安装

  2. 安装 Powershell7,选择 Powershell-版本号-win-x64.msi 的安装包,双击安装

  3. Powershell7 安装在C盘,Windows Terminal 会自动识别进去,其他盘需要自动添加(下图是其他盘的示例,命令行是安装的路径下的exe文件)

    Windows Terminal
    Windows Terminal

  4. 在 Windows Terminal 设置(快捷键:Ctrl+, )- 启动 - 默认配置文件:Powershell7,默认终端应用程序:Windows终端

    默认配置文件
    默认配置文件

  5. 在 Microsoft Store 搜索:oh my post 并安装(Oh My Posh官方教程

  6. nerd-fonts 选择字体,我个人使用的是 Anonymous Pro(点击直接下载),解压压缩包,选择ttf字体,右键 - 安装

  7. 在 Windows Terminal 设置- 默认值 - 外观 - 字体:AnonymousPro Nerd Font

    Windows Terminal 设置字体
    Windows Terminal 设置字体

  8. 在 Windows Terminal - Powershell7 输入命令:notepad $Profile 回车,默认第一回会提示,选择创建新文件,输入以下内容保存,输入 . $Profile来让配置生效:

    oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\powerlevel10k_lean.omp.json" | Invoke-Expression
  9. 输入命令:Get-PoshThemes 回车,会列举出所有主题,根据名称,修改上面内容 powerlevel10k_lean 为 你想修改的主题名称 ,修改完记得保存

    Get-PoshThemes
    Get-PoshThemes

  10. 新建一个标签页就能看到效果了。

Powershell配色

  1. 在 Windows Terminal 设置 - 打开 JSON 文件(左下角) - 将下面内容添加到 schemes 的 [] 里,保存
{
            "background": "#243435",
            "black": "#757575",
            "blue": "#4D7B82",
            "brightBlack": "#8A8A8A",
            "brightBlue": "#7AC3CF",
            "brightCyan": "#ADE0E0",
            "brightGreen": "#98D9AA",
            "brightPurple": "#D6B2A1",
            "brightRed": "#CF937A",
            "brightWhite": "#E0E0E0",
            "brightYellow": "#FAE79D",
            "cursorColor": "#FFFFFF",
            "cyan": "#729494",
            "foreground": "#D4E7D4",
            "green": "#728C62",
            "name": "Seafoam Pastel",
            "purple": "#8A7267",
            "red": "#825D4D",
            "selectionBackground": "#B00C11",
            "white": "#E0E0E0",
            "yellow": "#ADA16D"
        },
  1. Windows Terminal 设置 - 配色方案 - Seafoam Pastel - 设置为默认 - 保存

其他配色网站

Powershell插件

  1. 在 Powershell7 逐行输入回车,如果提示来源可能不受系统信任,输入 Y 信任即可。

    • PSReadLine:命令行编辑器

      • 语法着色
      • 语法错误提示
      • 命令补全
      • 自动保存历史命令
      • 交互式搜索历史命令
      • 智能提示
    • posh-git:一个提供 Git/PowerShell 集成的 PowerShell 模块。

    • Oh My Posh:用于美化和定制命令行提示符

    • ZLocation:用关键字直接跳到想去的资料夹,比使用 cd 更快速。

    • gsudo (sudo for windows):适用于 Windows 的 sudo

Install-Module -Name PSReadLine -AllowPrerelease -Force

Install-Module posh-git -Scope CurrentUser

Install-Module oh-my-posh -Scope CurrentUser

Install-Module ZLocation -Scope CurrentUser
  1. 在 Windows Terminal - Powershell7 输入命令:notepad $Profile 回车,输入以下内容保存,输入 . $Profile来让配置生效:
Import-Module PSReadLine
Import-Module posh-git
Import-Module ZLocation

可选配置

# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History 
# 设置 Tab 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete
# 每次回溯输入历史,光标定位于输入内容末尾
Set-PSReadLineOption -HistorySearchCursorMovesToEnd 
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward 
# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward 

非常感激每一位打赏的朋友!

支付宝扫码支持
微信扫码支持

扫一扫,请博主喝咖啡☕

文章作者: 斌仔
文章链接: https://www.wangdu.site/software/bianchengkaifa/2031.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 文武科技柜

相关推荐

共有 2 条评论

  1. obaby

    一直用 cmd 的路过,哈哈哈。都没怎么用过 ps

    1. 斌仔

      cmd 确实比自带的 ps 好用,但是没有提示啥的,有些命令跟 linux 还不太一样,就折腾一下,让 cmd 更好用了一些