chore: enhanced 080

This commit is contained in:
TaurusXin 2024-08-10 11:49:19 +08:00
parent 8975640b44
commit b73f64c0d6

View File

@ -1,6 +1,6 @@
---
title: "「Windows」别再用 CMD 了!换成 Windows Terminal + Powershell 7!"
categories: [ "windows" ]
categories: [ "Windows" ]
tags: [ "cmd", "terminal", "powershell"]
draft: false
slug: "windows-terminal"
@ -88,7 +88,7 @@ Windows 10 开始,微软便在系统内置了 PowerShell然而它只能运
打开 [PowerShell 7 的 GitHub Release](https://github.com/PowerShell/PowerShell/releases),下载 PowerShell-7.x.x-win-x64.msi (截止文章发布日期最新版本为 7.4.4)即可。
如果你不能顺利打开 GitHub那么可以使用我的 GitHub 镜像站链接下载,只要在下载链接前加上 https://ghcr.taurusxin.com/ 即可,例如 7.4.4 版本,那么链接就是 [https://ghcr.taurusxin.com/https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/PowerShell-7.4.4-win-x64.msi](https://ghcr.taurusxin.com/https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/PowerShell-7.4.4-win-x64.msi)。
如果你不能顺利打开 GitHub那么可以使用我的 GitHub 镜像站链接下载,只要在下载链接前加上 <https://ghcr.taurusxin.com/> 即可,例如 7.4.4 版本,那么链接就是 [https://ghcr.taurusxin.com/https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/PowerShell-7.4.4-win-x64.msi](https://ghcr.taurusxin.com/https://github.com/PowerShell/PowerShell/releases/download/v7.4.4/PowerShell-7.4.4-win-x64.msi)。
下载打开后一路 Next 即可安装完成。
@ -114,7 +114,7 @@ Windows 10 开始,微软便在系统内置了 PowerShell然而它只能运
### 安装一个 Nerd Font
Shell 下有一些带有特殊符号的主题,这时如果使用默认的 Consola 字体就会显示乱码,所以在配置 oh-my-posh 前,我们需要一个 `Nerd Font`,它为现有的字体打了一个补丁,支持了那些特殊符号,我们可以前往 [https://www.nerdfonts.com/font-downloads](https://www.nerdfonts.com/font-downloads) 选择一个你喜欢的终端字体,然后下载安装就可以了,我喜欢使用和写代码一样的 JetBrains Mono 字体,于是就选择了 JetBrainsMono Nerd Font。
oh-my-posh 下有一些带有图标或者特殊符号的主题,这时如果使用默认的 Consola 字体就会显示乱码,所以在配置 oh-my-posh 前,我们需要一个 `Nerd Font`,它为现有的字体打了一个补丁,支持了那些特殊符号,我们可以前往 [https://www.nerdfonts.com/font-downloads](https://www.nerdfonts.com/font-downloads) 选择一个你喜欢的终端字体,然后下载安装就可以了,我喜欢使用和写代码一样的 JetBrains Mono 字体,于是就选择了 JetBrainsMono Nerd Font。
![JetBrainsMono Nerd Font](https://cdn.taurusxin.com/hugo/2024/08/09/jetbrainsmono-nerdfont.png)
@ -142,10 +142,16 @@ code $PROFILE
oh-my-posh init pwsh | Invoke-Expression
```
重启 Windows Terminal 或者打开一个新的 PowerShell 7 标签后,此时它应该长这样.
重启 Windows Terminal 或者打开一个新的 PowerShell 7 标签后,此时它应该长这样
![激活 oh-my-posh](https://cdn.taurusxin.com/hugo/2024/08/09/ohmyposh-activated.png)
你也可以用下面的命令使得配置文件立即生效。
```powershell
. $PROFILE
```
现在是不是比一个黑黑的窗口好看多了,当然 oh-my-posh 也内置了很多其它主题,你可以浏览[这个链接](https://ohmyposh.dev/docs/themes)或者输入下面的命令来找一个你喜欢的主题,会输出每个主题对应的名称。
```powershell
@ -158,7 +164,7 @@ Get-PoshThemes
& ([ScriptBlock]::Create((oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\ys.omp.json" --print) -join "`n"))
```
打开一个新的标签,它就换好啦
打开一个新的标签页,或者使用 `. $PROFILE` 命令使配置文件生效
![ys 主题](https://cdn.taurusxin.com/hugo/2024/08/09/omp-ys-theme.png)
@ -195,6 +201,14 @@ Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit
# 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
# 使用 ls 和 ll 查看目录
function ListDirectory {
(Get-ChildItem).Name
Write-Host("")
}
Set-Alias -Name ls -Value ListDirectory
Set-Alias -Name ll -Value Get-ChildItem
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
@ -215,7 +229,16 @@ function touch {
(Get-Item $path).LastWriteTime = Get-Date
}
}
Set-Alias touch New-Item
```
注意posh-git 插件需要先进行安装。
```powershell
# 先设置允许允许远程代码执行策略
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm
# 安装 posh-git 模块
PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force
```
## 结语