shenjack-profile/PowerShell/Microsoft.PowerShell_profile.ps1

62 lines
1.8 KiB
PowerShell
Raw Normal View History

2023-10-21 01:17:07 +08:00
# 引入 Terminal-Icons
Import-Module Terminal-Icons
# 引入 PSReadLine
Import-Module PSReadLine
# 设置 PS readline
Set-PSReadLineOption -EditMode Windows
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle ListView
Set-PSReadLineOption -BellStyle None
# 设置 Tab 键补全
Set-PSReadlineKeyHandler -Key Tab -Function Complete
# 设置 Ctrl+z 为撤销
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
2023-10-21 01:23:11 +08:00
# 设置 Ctrl+d 为菜单补全和 Intellisense
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete
2023-10-21 01:17:07 +08:00
# 设置向上键为后向搜索历史记录
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
# 设置向下键为前向搜索历史纪录
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
2023-10-21 02:01:56 +08:00
function pythons {
(8, 9, 10, 11, 12) | ForEach-Object {
2023-10-21 11:53:23 +08:00
&"python3.$_ $args"
2023-10-21 02:01:56 +08:00
}
}
2023-10-21 01:17:07 +08:00
# 如果是 windows 平台 则执行 windows 下的配置
if ($IsWindows) {
# Windows 下的 java
foreach ($java_version in 8, 16, 17) {
Invoke-Expression @"
function j$java_version {
if (`$args.Length -eq 0) {
Write-Output "Java $java_version"
`$env:java_home="C:\Program Files\BellSoft\LibericaJDK-$java_version-Full"
`$env:path="`$env:java_home\bin;`$env:path"
} else {
&"C:\Program Files\BellSoft\LibericaJDK-$java_version-Full\bin\java.exe" (`$args -join " ")
}
}
"@
}
# Windows 下的 vcpkg 初始化
Import-Module 'V:\githubs\vcpkg\scripts\posh-vcpkg'
Write-Host "loaded Windows only profile"
}
# 设置 ll 为 lsd -la
function ll {
lsd -la $args
}
# 防止有的平台没有 cls 的快捷方式
Set-Alias -Name cls -Value clear
# 启动 starship
Invoke-Expression (&starship init powershell)