Created
April 3, 2025 09:06
-
-
Save Jayonics/a84be1d4289322e14c4b78a8305039f2 to your computer and use it in GitHub Desktop.
Multi PowerShell edition PowerShell profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # # oh-my-posh theme # # # | |
if ($env:TERM_PROGRAM -eq "vscode") { . "$(code --locate-shell-integration-path pwsh)" } | |
if ($env:TERMINAL_EMULATOR -eq "JetBrains-JediTerm") { oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\honukai.json" | Invoke-Expression } | |
$vsprofile = oh-my-posh get shell | |
if ($vsprofile -ne "devenv") { | |
switch ($PSEdition) { | |
"Core" { | |
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\microverse-power.omp.json" | Invoke-Expression | |
} | |
"Desktop" { | |
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\atomicBit.omp.json" | Invoke-Expression | |
} | |
default { | |
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\microverse-power.omp.json" | Invoke-Expression | |
} | |
} | |
} | |
# # # PSReadLine Configuration # # # | |
# Check if the console supports VT escape sequences | |
if ($Host.UI.SupportsVirtualTerminal) { | |
Set-PSReadLineKeyHandler -Key Tab -Function:MenuComplete | |
# # # History based search | |
Set-PSReadLineOption -PredictionViewStyle 'ListView' | |
Set-PSReadLineOption -ShowToolTips | |
# If the shell is Windows PowerShell (5.1 or lower), HistoryAndPlugin is not supported, use History instead | |
switch ($PSEdition) { | |
"Core" { | |
Set-PSReadLineOption -PredictionSource HistoryAndPlugin | |
} | |
"Desktop" { | |
Set-PSReadLineOption -PredictionSource History | |
} | |
} | |
Set-PSReadLineOption -HistorySaveStyle SaveIncrementally | |
# Autocompletion for arrow keys | |
# Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | |
# Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | |
} | |
else { | |
Write-Verbose "The console does not support VT escape sequences" | |
} | |
<# { | |
[Object[]]$jhGroup = @("jh-win-svr2", "jh-win-pc1", "jh-asus-lap1") | |
function jhCommand { | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $false)] | |
[Object[]]$Computers = $jhGroup, | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
$Command | |
) | |
foreach ($Computer in $Computers) { | |
Write-Host -ForegroundColor:Magenta "Computer: $" | |
Invoke-Command -ComputerName "$Computer" -ScriptBlock { $Command } | |
if ($?) { | |
Write-Verbose -ForegroundColor:Green "Command successfull." | |
} | |
elseif (!$?) { | |
Write-Error -ForegroundColor:Red "Command unsuccessfull." | |
} | |
} | |
} | |
} #> | |
# # # Module Imports # # # | |
Import-Module oh-my-posh -ErrorAction SilentlyContinue | |
Import-Module Terminal-Icons -ErrorAction SilentlyContinue | |
Import-Module posh-git -ErrorAction SilentlyContinue | |
Import-Module CompletionPredictor -ErrorAction SilentlyContinue | |
# # # Argument Completers # # # | |
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock { | |
param($wordToComplete, $commandAst, $cursorPosition) | |
[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new() | |
$Local:word = $wordToComplete.Replace('"', '""') | |
$Local:ast = $commandAst.ToString().Replace('"', '""') | |
winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object { | |
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | |
} | |
} | |
Register-ArgumentCompleter -Native -CommandName az -ScriptBlock { | |
param($commandName, $wordToComplete, $cursorPosition) | |
$completion_file = New-TemporaryFile | |
$env:ARGCOMPLETE_USE_TEMPFILES = 1 | |
$env:_ARGCOMPLETE_STDOUT_FILENAME = $completion_file | |
$env:COMP_LINE = $wordToComplete | |
$env:COMP_POINT = $cursorPosition | |
$env:_ARGCOMPLETE = 1 | |
$env:_ARGCOMPLETE_SUPPRESS_SPACE = 0 | |
$env:_ARGCOMPLETE_IFS = "`n" | |
$env:_ARGCOMPLETE_SHELL = 'powershell' | |
az 2>&1 | Out-Null | |
Get-Content $completion_file | Sort-Object | ForEach-Object { | |
[System.Management.Automation.CompletionResult]::new($_, $_, "ParameterValue", $_) | |
} | |
Remove-Item $completion_file, Env:\_ARGCOMPLETE_STDOUT_FILENAME, Env:\ARGCOMPLETE_USE_TEMPFILES, Env:\COMP_LINE, Env:\COMP_POINT, Env:\_ARGCOMPLETE, Env:\_ARGCOMPLETE_SUPPRESS_SPACE, Env:\_ARGCOMPLETE_IFS, Env:\_ARGCOMPLETE_SHELL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment