简单定制化PowerShell
孙泽辉 Lv5

美化Powershell,为其添加命令别名。

安装美化工具:

Starship:可用于各种 Shell 的提示符

我系统里有cargo,直接一行命令装上了。

步骤我就不贴了,一定要注意换成 Nerd Font (opens new window)的字体,不然有些图标显示不出来,切换方法:

image image

配置命令别名

输入echo $profile

1
2
echo $profile
C:\Users\孙泽辉\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

打开后缀是ps1的文件,像我这样添加别名

1
2
3
4
5
6
7
8
9
10
# 删除默认别名
Remove-Item Alias:ni -Force
# 添加别名
function ni {
pnpm install
}
function np {
hexo new post $args
}
Invoke-Expression (&starship init powershell) # Initialize Starship

这个文件会在Session建立的时候执行,可以添加你想写的脚本

ni 是系统已经占用的了,所以我先把他删了后添加

效果:

image

添加历史记录提示

这种效果

image

PowerShell/PSReadLine: A bash inspired readline implementation for PowerShell (github.com)

配置步骤:

安装最新版PowerShellGet(必装)

1
Install-Module -Name PowerShellGet -Force

安装提示插件

1
Install-Module PSReadLine -AllowPrerelease -Force

在之前Microsoft.PowerShell_profile.ps1中,添加

1
2
Set-PSReadLineOption -PredictionSource History # 设置预测文本来源为历史记录
Set-PSReadlineKeyHandler -Chord Tab -Function MenuComplete # 面板展示联想

参考:

缩短命令、调整按键、自动补全,这些代码值得你放进 PowerShell 配置文件 - 少数派 (sspai.com)

 Comments
Comment plugin failed to load
Loading comment plugin
Powered by Hexo & Theme Keep
Total words 85.5k