[TOC]
# 安装 powershell 最新版本
windows 默认的 powershell 版本很低
```
scoop install -g main/pwsh
```
可以使用 该 pwsh 配置 Terminal
# PowerShell 配置文件
检查您是否已有 PowerShell Profile:
```
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE # 用记事本编辑
```
# 配置文件内容
```
Import-Module posh-git
$GitPromptSettings.EnableFileStatus = $false
$GitPromptSettings.DefaultPromptPrefix.Text = '$(Get-Date -f "MM-dd HH:mm:ss") '
$GitPromptSettings.DefaultPromptPrefix.ForegroundColor = [ConsoleColor]::Magenta
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true
$GitPromptSettings.DefaultPromptPath.ForegroundColor = 'Orange'
$GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n'
$GitPromptSettings.DefaultPromptWriteStatusFirst = $true
# 起始位置
set-location D:\YXT
# 将PowerShell窗口的标题更改为SysadminGeek
$shell.WindowTitle="SysadminGeek"
# 更改背景和文本的颜色:
# $shell.BackgroundColor ="Gray"
# $shell.ForegroundColor = "Black"
# ------------------设置别名-----------------------
new-item alias:edit -value notepad3.exe
# 清除主机
# Clear-Host
#-------------------PSReadline------------------------
# 设置 Tab 键补全
Set-PSReadlineKeyHandler -Key Tab -Function Complete
# 设置 Ctrl+d 为菜单补全和 Intellisense #
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete
# 设置 Ctrl+d 为退出
PowerShell Set-PSReadlineKeyHandler -Key "Ctrl+d" -Function ViExit
# 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
# 一些 PSReadline 配置
$PSReadLineOptions = @{
EditMode = "Emacs"
HistoryNoDuplicates = $true
HistorySearchCursorMovesToEnd = $true
Colors = @{
# 提示文字颜色,原来的颜色太浅了,我这里换了
Prediction = '#8F8B8B'
}
}
Set-PSReadLineOption @PSReadLineOptions
#-------------------------starship--------------------------
Invoke-Expression (&starship init powershell)
```
# 参考
[Windows Terminal + PowerShell 的配置 - 丏谷 | Miangu Blog (zhangtianrong.github.io)](https://zhangtianrong.github.io/2020/01/09/WT+POSH/)