powershell7升级笔记

https://learn.microsoft.com/zh-cn/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.3#msi

安装powershell7

法一:

推荐MSI安装方式,全打钩,可以自动配置环境变量和右键菜单

https://learn.microsoft.com/zh-cn/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.3#install-powershell-using-winget-recommended

法二:

打开powershell管理员模式

# 搜索最新版本的 PowerShell
winget search Microsoft.PowerShell
# 使用 id 参数安装 PowerShell 或 PowerShell 预览版(以下二选一)
winget install --id Microsoft.Powershell --source winget	#推荐
winget install --id Microsoft.Powershell.Preview --source winget

安装成功后,在开始菜单里即可找到powershell7

安装Windows terminal

在Microsoft store中安装Windows终端

安装字体

https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/FiraCode.zip

(推荐)Fira Code Medium Nerd Font Complete.ttf

安装powershell插件

# 0.允许使用脚本 
Install-Module -Name PowerShellGet -Force

# 1. 安装 PSReadline 包,该插件可以让命令行很好用,类似 zsh
Install-Module -Name PSReadLine  -Scope CurrentUser

# 2. 安装 posh-git 包,让你的 git 更好用
PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force

# 3. 安装 oh-my-posh 包,让你的命令行更酷炫、优雅
winget install JanDeDobbeleer.OhMyPosh -s winget

修改配置文件

Microsoft.PowerShell_profile.ps1

notepad $PROFILE

修改为以下内容

注意,第一行中%UserName%改为你所在处用户的名称(不修改也能用,不过默认第一个主题)

oh-my-posh init pwsh --config 'C:\Users\%UserName%\AppData\Local\Programs\oh-my-posh\themes\ys.omp.json' | Invoke-Expression
New-Alias -Name ifconfig -Value ipconfig
function sqlmap{
	python D:\tools\sqlmap\sqlmap.py @Args
}

# Import the Chocolatey Profile that contains the necessary code to enable
# tab-completions to function for `choco`.
# Be aware that if you are missing these lines from your profile, tab completion
# for `choco` will not function.
# See https://ch0.co/tab-completion for details.
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
  Import-Module "$ChocolateyProfile"
}
# 命令补全部分
# Shows navigable menu of all options when hitting Tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
#
# # Autocompletion for arrow keys
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
Import-Module PSReadLine
#Install-Module -Name PSReadLine -AllowClobber -Force
Set-PSReadLineOption -PredictionSource History

Get-PoshThemes可以查看所有主题,修改第一行主题配置文件路径即可应用

安装scoop包管理工具

https://juejin.cn/post/7155708362829594632

set-executionpolicy remotesigned -scope currentuser
iwr -useb get.scoop.sh | iex

若上面用不了,则看下面

set-executionpolicy remotesigned -scope currentuser
wget -c "https://get.scoop.sh" -O install.ps1
./install.ps1 -?
.\install.ps1
posted @ 2024-05-21 14:54  DumpInfou  阅读(225)  评论(0编辑  收藏  举报