当前位置:   article > 正文

记一次配置Windows终端terminal_最新发布页

最新发布页

立即安装Windows终端terminal

Git发布页面

发布地址 https://github.com/microsoft/terminal/releases

应用商店

安装地址 https://aka.ms/terminal

winget

winget install --id=Microsoft.WindowsTerminal -e

如果提示winget : 无法将“winget”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。

如未安装winget,安装地址 https://www.microsoft.com/p/app-installer/9nblggh4nns1#activetab=pivot:overviewtab

如已安装,可能是因为没有将winget添加到环境变量中,可以添加下,或者试试下面这条命令

%LOCALAPPDATA%\Microsoft\WindowsApps\winget install --id=Microsoft.WindowsTerminal -e

安装 Oh My Posh

安装前的注意事项

Windows PowerShell 执行策略

在执行 winget install 命令之前,先查看下,Windows PowerShell 的执行策略

执行策略 是 Windows PowerShell安全策略中的一部分,它将决定你是否可以载入配置文件(包括你的 Windows PowerShell profile文件)和运行脚本,它将会在运行前确定哪些文件必须具有数字签名(digitally signed)

执行策略状态说明

  1. `Restricted` 表示状态是禁止的 不载入配置文件, 不执行脚本. Restricted 是默认值.
  2. `RemoteSigned` 所有从互联网上下载的脚本必须通过信任的出版商签名(trusted publisher)
  3. `AllSigned` 所有的配置文件和脚本必须通过信任的出版商签名(trusted publisher),这里所指的脚本页包括在本地计算机上创建的脚本
  4. `Unrestricted` 载入所有的配置文件和脚本,如果运行了一个从互联网上下载且没有数字签名的脚本,在执行前都会被提示是否执行
  1. // 获取 Windows PowerShell 当前执行策略get-ExecutionPolicy
  2. // 修改 Windows PowerShell 中执行策略set-ExecutionPolicy RemoteSigned

开始安装

官网链接 https://ohmyposh.dev

发布页下载 https://github.com/JanDeDobbeleer/oh-my-posh/releases/

或者终端执行命令

  1. // oh-my-posh 安装命令
  2. winget install JanDeDobbeleer.OhMyPosh
  3. // oh-my-posh 更新命令
  4. winget upgrade JanDeDobbeleer.OhMyPosh
  5. //可在命令后追加-s winget --location D:\OhMyPosh来设置路径//如 winget install JanDeDobbeleer.OhMyPosh -s winget --location D:\OhMyPosh
PS:安装成功后需要重新打开终端,才能继续后续的操作

安装 Nerd Fonts 字体解决乱码

Nerd Fonts字体中包含了大量的Icon图标

官网地址 https://www.nerdfonts.com/

releases页面 https://github.com/ryanoasis/nerd-fonts/releases/tag/v2.3.1

官方推荐使用的是Meslo,我使用的是MesloLGM NF

下载后解压丢到C:\Windows\Fonts目录即可完成安装过

打开 终端->设置->外观->字体 进行修改

智能补全/智能提示

效果类似于mac的iterm2

PowerShell 7.2 随 PSReadLine 2.1.0 一起提供。 有较新版本可用。 可以在 Windows PowerShell 5.1 及更新版本上安装和使用 PSReadLine 的当前版本。 对于某些功能,需要运行 PowerShell 7.2 或更高版本。

PSReadLine 为 PowerShell 控制台提供强大的命令行编辑体验。 提供以下功能:

  • 命令行的语法着色

  • 语法错误的直观指示

  • 编辑和历史记录) (更好的多行体验

  • 可自定义的键绑定

  • Cmd 和 Emacs 模式

  • 许多配置选项

  • Bash 样式完成在 Cmd 模式下 (可选,在 Emacs 模式下默认)

  • 埃马克扬克/杀环

  • 基于 PowerShell 令牌的“word”移动和删除

  • 预测 IntelliSense

  • 在控制台中动态显示“帮助”,而不会丢失命令行上的位置

PSReadLine 需要 PowerShell 5.1 或更高版本。 PSReadLine 适用于默认的 Windows 控制台主机、窗口终端和Visual Studio Code。 它在Windows PowerShell ISE 中不起作用。

可以从PowerShell 库安装 PSReadLine。 若要在受支持的 PowerShell 版本中安装 PSReadLine,请运行以下命令。

Install-Module-Name PSReadLine -AllowClobber -Force

预测 IntelliSense

预测 IntelliSense 是选项卡完成概念的补充,可帮助用户成功完成命令。 它使用户能够基于用户历史记录和其他特定于域的插件的匹配预测发现、编辑和执行完整命令。

启用预测 IntelliSense

预测性 IntelliSense 默认禁用。 若要启用预测,只需运行以下命令:

Set-PSReadLineOption-PredictionSourceHistory

PredictionSource 参数还可以接受特定于域和自定义要求的插件。

若要禁用预测 IntelliSense,只需运行:

Set-PSReadLineOption-PredictionSource None

更多配置,可以放在配置文件中,让其每次都生效

  1. # Shows navigable menu of all options when hitting TabSet-PSReadlineKeyHandler -Key Tab -Function MenuComplete
  2. # Autocompletion for arrow keysSet-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
  3. Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

配置文件

终端执行

code $PROFILE

首次使用,可能不存在该文件,保存即可

  1. # 去除 Window PowerShell 版权所有提示
  2. clear
  3. # 配置 oh-my-posh 其中kali为主题名,可以执行get-Poshthemes获取主题列表
  4. oh-my-posh init pwsh --config 'C:\Users\Administrator\AppData\Local\Programs\oh-my-posh\themes\kali.omp.json' | Invoke-Expression
  5. # Shows navigable menu of all options when hitting TabSet-PSReadlineKeyHandler -Key Tab -Function MenuComplete
  6. # Autocompletion for arrow keysSet-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
  7. Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward

自定义命令

您可以在配置文件中写一些常用的命令来快捷操作,如

  1. # 使用 vscode 打开 $PROFILE 配置文件function vscodeOpen {
  2. Code $PROFILE
  3. }
  4. # 使用 nodepad++ 打开 $PROFILE 配置文件function notepadOpen {
  5. noetepad $PROFILE
  6. }

Git 查看差异和打包差异

  1. # git
  2. function git-diff ([string]$commitid) {
  3. if ($commitid -eq "")
  4. {
  5. Write-Output "No CommitId"
  6. return
  7. }
  8. git diff $commitid head --stat
  9. }
  10. function git-archive ([string]$commitid) {
  11. if ($commitid -eq "")
  12. {
  13. Write-Output "No CommitId"
  14. return
  15. }
  16. Write-Output "git archive $commitid to C:\Users\Administrator\Desktop\up\export.zip"
  17. git archive -o C:\Users\Administrator\Desktop\up\export.zip head $(git diff --name-only $commitid head)
  18. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/185933
推荐阅读
相关标签
  

闽ICP备14008679号