# window powershell 下使用 oh-my-zsh

### 下载powershell7

[powershell7 download](https://github.com/PowerShell/powershell/releases)

### 安装一些特殊字体

```plaintext
# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install

cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts
```

#### 推荐字体库

[nerdfonts](https://www.nerdfonts.com/font-downloads) （用于解决powershell 图标乱码问题） 我使用的是 `Hank Nerd Font Mono`

### 安装 oh-my-posh

```plaintext
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser
Install-Module posh-docker -Scope CurrentUser
```

### vscode 打开每次启动powershell的配置项

```plaintext
code $profile
```

#### 注入以下代码 并保存

```sh
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme powerlevel10k
```

```sh
 #or 旧版本powershell
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme powerlevel10k
```

#### 允许自定义撰写脚本

```plaintext
set-ExecutionPolicy RemoteSigned
```

### windows terminal 展示效果

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1637509920685/Ad7-5ague.png align="left")

### vscode 下使用 增加字体规则

```json
{
    "terminal.integrated.fontFamily": "Hank Nerd Font Mono",
}
```

### vscode terminal 展示效果

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1658281630625/XYQI7vKpW.png align="left")

### 2023-01-09 新增

使用 PSReadLine 代码提示 \`\`\`plaintext

# powershell 注入以下代码 安装

Install-Module PSReadLine -Force \`\`\`

### 安装完成后修改 $profile

```plaintext
code $profile
```

```plaintext
# 引入与设置终端主题
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme powerlevel10k 

# 2023-01-09 新增
# PSReadLine
Import-Module PSReadLine
# Enable Prediction History
Set-PSReadLineOption -PredictionSource History
# Advanced Autocompletion for arrow keys 方向键检索历史
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward 
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
```

### 效果图(使用F2切换`InlineView` 和 `ListView` 模式)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1673229121306/d659b059-04fa-4643-b663-d38c6a4d2671.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1673245879647/c23974a7-369a-401f-a94e-4dce928d115f.png align="center")

### 文献

### [microsoft powershell](https://learn.microsoft.com/zh-cn/powershell/scripting/learn/shell/using-predictors?view=powershell-7.3)

[ohmyposh](https://ohmyposh.dev/docs/installation/windows)
