先更新一下终端和powershell

终端官方:https://github.com/microsoft/terminal

powershell官方:GitHub - PowerShell/PowerShell

上网困难的童鞋请用国内下载:

下载终端

下载powershell

打开终端,按ctrl+,打开设置

关闭,重新打开使设置生效。

准备工作做好了,接下来开美化。

安装 Oh My Posh

如果以前安装过,请先卸载

Remove-Item $env:POSH_PATH -Force -Recurse
删除配置文件$profile中的 Import-Module oh-my-posh


如果没有请忽略。

全新安装步骤:

打开终端,现在默认什么启动powershell,运行如下命令:

winget install JanDeDobbeleer.OhMyPosh -s winget
如图,表示安装成功


重新打开终端,发现并没什么变化。这是因为还没修改配置文件。

在设置配置文件前,因为有些主题需要特定字体,我们来安装一下字体

运行如下命令安装体

oh-my-posh font install

如果出现上面提示,请设置成以管理员运行powershell,参考下图设置(按ctrl+,)打开设置
保存好,重新打开终端 ,然后再次运行刚才 的命令。

出现如图画面,按光标上下键选择要安装的字体。我安装的是meslo,当然你可以安装多个字体,看你喜欢哪个还有就是有些主题需要哪个。

上网困难的童鞋,点 Meslo 国内下载,手动下载,安装。

安装成功后,打开终端设置,字体 


好了,接下来我们设置配置文件。

创建配置文件 

New-Item -Path $PROFILE -Type File -Force
编辑配置文件
notepad $PROFILE

粘贴如下内容:
#------------------------------- Import Modules BEGIN -------------------------------
# 引入 posh-git
Import-Module posh-git
# 引入 oh-my-posh
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/peru.omp.json" | Invoke-Expression
# 引入 ps-read-line
Import-Module PSReadLine



重新打开终端或执行 . $PROFILE
看看是不是变漂亮了。,要改变主题及设置,编辑 $PROFILE就可以了。
主题 peru.omp.json 就是主题名称,修这里就可以了。可以用 get-poshthemes 查看所有内置主题,选择你自己喜欢的。 以下是我的$profile供参考

#------------------------------- Import Modules BEGIN -------------------------------
# 引入 posh-git
Import-Module posh-git

# 引入 oh-my-posh
#oh-my-posh init pwsh | Invoke-Expression
#oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/peru.omp.json" | Invoke-Expression
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH/peru.omp.json" | Invoke-Expression

# 引入 ps-read-line
Import-Module PSReadLine


#------------------------------- Import Modules END   -------------------------------





#-------------------------------  Set Hot-keys BEGIN  -------------------------------
# 设置预测文本来源为历史记录
Set-PSReadLineOption -PredictionSource History

# 每次回溯输入历史,光标定位于输入内容末尾
Set-PSReadLineOption -HistorySearchCursorMovesToEnd

# 设置 Tab 为菜单补全和 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
#-------------------------------  Set Hot-keys END    -------------------------------





#-------------------------------    Functions BEGIN   -------------------------------
# Python 直接执行
$env:PATHEXT += ";.py"

# 更新系统组件
function Update-Packages {
	# update pip
	Write-Host "Step 1: 更新 pip" -ForegroundColor Magenta -BackgroundColor Cyan
	$a = pip list --outdated
	$num_package = $a.Length - 2
	for ($i = 0; $i -lt $num_package; $i++) {
		$tmp = ($a[2 + $i].Split(" "))[0]
		pip install -U $tmp
	}

	# update TeX Live
	$CurrentYear = Get-Date -Format yyyy
	Write-Host "Step 2: 更新 TeX Live" $CurrentYear -ForegroundColor Magenta -BackgroundColor Cyan
	tlmgr update --self
	tlmgr update --all

	# update Chocolotey
	Write-Host "Step 3: 更新 Chocolatey" -ForegroundColor Magenta -BackgroundColor Cyan
	choco outdated
}
#-------------------------------    Functions END     -------------------------------





#-------------------------------   Set Alias BEGIN    -------------------------------
# 1. 编译函数 make
function MakeThings {
	nmake.exe $args -nologo
}
Set-Alias -Name make -Value MakeThings

# 2. 更新系统 os-update
Set-Alias -Name os-update -Value Update-Packages

# 3. 查看目录 ls & ll
function ListDirectory {
	(Get-ChildItem).Name
	Write-Host("")
}
Set-Alias -Name ls -Value ListDirectory
Set-Alias -Name ll -Value Get-ChildItem

# 4. 打开当前工作目录
function OpenCurrentFolder {
	param
	(
		# 输入要打开的路径
		# 用法示例:open C:\
		# 默认路径:当前工作文件夹
		$Path = '.'
	)
	Invoke-Item $Path
}
Set-Alias -Name open -Value OpenCurrentFolder
#-------------------------------    Set Alias END     -------------------------------





#-------------------------------   Set Network BEGIN    -------------------------------
# 1. 获取所有 Network Interface
function Get-AllNic {
	Get-NetAdapter | Sort-Object -Property MacAddress
}
Set-Alias -Name getnic -Value Get-AllNic

# 2. 获取 IPv4 关键路由
function Get-IPv4Routes {
	Get-NetRoute -AddressFamily IPv4 | Where-Object -FilterScript {$_.NextHop -ne '0.0.0.0'}
}
Set-Alias -Name getip -Value Get-IPv4Routes

# 3. 获取 IPv6 关键路由
function Get-IPv6Routes {
	Get-NetRoute -AddressFamily IPv6 | Where-Object -FilterScript {$_.NextHop -ne '::'}
}
Set-Alias -Name getip6 -Value Get-IPv6Routes

# 4. 获取DNS
function Get-Dns{
	$(get-netipconfiguration).dnsserver
}
Set-Alias -Name getdns -Value Get-Dns
#-------------------------------    Set Network END     -----------------------------


*tips

点赞(1) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部