window powershell 下使用 oh-my-zsh

  
1 min read

下载powershell7

powershell7 download

安装一些特殊字体

# 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 (用于解决powershell 图标乱码问题) 我使用的是 Hank Nerd Font Mono

安装 oh-my-posh

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

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

code $profile

注入以下代码 并保存

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

允许自定义撰写脚本

set-ExecutionPolicy RemoteSigned

windows terminal 展示效果

image.png

vscode 下使用 增加字体规则

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

vscode terminal 展示效果

image.png

2023-01-09 新增

使用 PSReadLine 代码提示 ```plaintext

powershell 注入以下代码 安装

Install-Module PSReadLine -Force ```

安装完成后修改 $profile

code $profile
# 引入与设置终端主题
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切换InlineViewListView 模式)

文献

microsoft powershell

ohmyposh

0
Subscribe to my newsletter

Read articles from   directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by