79 lines
2.4 KiB
PowerShell
79 lines
2.4 KiB
PowerShell
# 引入 Terminal-Icons
|
|
Import-Module Terminal-Icons
|
|
# 引入 PSReadLine
|
|
Import-Module PSReadLine
|
|
|
|
# 设置 PS readline
|
|
Set-PSReadLineOption -EditMode Windows
|
|
Set-PSReadLineOption -PredictionViewStyle ListView
|
|
Set-PSReadLineOption -BellStyle None
|
|
# 设置 Tab 键补全
|
|
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
|
|
# 设置 Ctrl+z 为撤销
|
|
Set-PSReadLineKeyHandler -Key "Ctrl+z" -Function Undo
|
|
# 设置 Ctrl+d 为菜单补全和 Intellisense
|
|
# Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete
|
|
# 设置向上键为后向搜索历史记录
|
|
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
|
|
# 设置向下键为前向搜索历史纪录
|
|
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
|
|
|
|
# 判断 PowerShell 版本
|
|
if ($PSVersionTable.PSVersion.Major -lt 7) {
|
|
Set-PSReadLineOption -PredictionSource History
|
|
}
|
|
else {
|
|
Set-PSReadLineOption -PredictionSource HistoryAndPlugin
|
|
}
|
|
|
|
function pythons {
|
|
(8, 9, 10, 11, 12) | ForEach-Object {
|
|
&"python3.$_ $args"
|
|
}
|
|
}
|
|
|
|
# 如果是 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'
|
|
|
|
# Windows 10 only
|
|
$is_windows_10 = [System.Environment]::OSVersion.Version.Major -eq "10"
|
|
if ($is_windows_10) {
|
|
# https://github.com/PowerShell/PowerShell/issues/13138
|
|
# 其实就是 patch 成 import-module appx -usewindowspowershell
|
|
$PSDefaultParameterValues['Import-Module:UseWindowsPowerShell'] = {
|
|
if ((Get-PSCallStack)[1].Position.Text -match '\bAppX\b') { $true }
|
|
}
|
|
Write-Host "loaded Windows 10 only profile"
|
|
}
|
|
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) |