Created
November 23, 2021 13:09
-
-
Save fabianobizarro/0508e825d9e943b37f53a6d13a23d262 to your computer and use it in GitHub Desktop.
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
{ | |
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", | |
"final_space": true, | |
"console_title": true, | |
"console_title_style": "folder", | |
"blocks": [ | |
{ | |
"type": "prompt", | |
"alignment": "left", | |
"horizontal_offset": 0, | |
"vertical_offset": 0, | |
"segments": [ | |
{ | |
"type": "path", | |
"style": "diamond", | |
"powerline_symbol": "", | |
"invert_powerline": false, | |
"foreground": "#ffffff", | |
"background": "#ff479c", | |
"leading_diamond": "", | |
"trailing_diamond": "", | |
"properties": { | |
"prefix": " ", | |
"style": "folder" | |
} | |
}, | |
{ | |
"type": "git", | |
"style": "powerline", | |
"powerline_symbol": "", | |
"invert_powerline": false, | |
"foreground": "#193549", | |
"background": "#fffb38", | |
"leading_diamond": "", | |
"trailing_diamond": "", | |
"properties": { | |
"display_status": true, | |
"display_stash_count": true, | |
"display_upstream_icon": true | |
} | |
}, | |
{ | |
"type": "dotnet", | |
"style": "powerline", | |
"powerline_symbol": "", | |
"invert_powerline": false, | |
"foreground": "#000000", | |
"background": "#6CA35E", | |
"leading_diamond": "", | |
"trailing_diamond": "", | |
"properties": { | |
"display_version": true, | |
"prefix": " " | |
} | |
}, | |
{ | |
"type": "node", | |
"style": "powerline", | |
"powerline_symbol": "\uE0B0", | |
"foreground": "#ffffff", | |
"background": "#6CA35E", | |
"properties": { | |
"prefix": " \uE718 " | |
} | |
}, | |
{ | |
"type": "exit", | |
"style": "powerline", | |
"powerline_symbol": "", | |
"invert_powerline": false, | |
"foreground": "#ffffff", | |
"background": "#2e9599", | |
"leading_diamond": "", | |
"trailing_diamond": "", | |
"properties": { | |
"always_enabled": true, | |
"color_background": true, | |
"display_exit_code": false, | |
"error_color": "#f1184c", | |
"prefix": " " | |
} | |
} | |
] | |
} | |
] | |
} |
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 config | |
oh-my-posh --init --shell pwsh --config ~/.config/ohmyposh.config.json | Invoke-Expression | |
# Terminal Icons | |
Import-Module -Name Terminal-Icons | |
#region ENVs | |
#$env:Path += "<your_custom_env>" | |
# PSReadLine | |
if ($host.Name -eq 'ConsoleHost') | |
{ | |
Import-Module PSReadLine | |
} | |
Set-PSReadLineOption -PredictionSource History | |
Set-PSReadLineOption -PredictionViewStyle ListView | |
Set-PSReadLineOption -EditMode Windows | |
Set-PSReadLineKeyHandler -Key F7 ` | |
-BriefDescription History ` | |
-LongDescription 'Show command history' ` | |
-ScriptBlock { | |
$pattern = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$pattern, [ref]$null) | |
if ($pattern) | |
{ | |
$pattern = [regex]::Escape($pattern) | |
} | |
$history = [System.Collections.ArrayList]@( | |
$last = '' | |
$lines = '' | |
foreach ($line in [System.IO.File]::ReadLines((Get-PSReadLineOption).HistorySavePath)) | |
{ | |
if ($line.EndsWith('`')) | |
{ | |
$line = $line.Substring(0, $line.Length - 1) | |
$lines = if ($lines) | |
{ | |
"$lines`n$line" | |
} | |
else | |
{ | |
$line | |
} | |
continue | |
} | |
if ($lines) | |
{ | |
$line = "$lines`n$line" | |
$lines = '' | |
} | |
if (($line -cne $last) -and (!$pattern -or ($line -match $pattern))) | |
{ | |
$last = $line | |
$line | |
} | |
} | |
) | |
$history.Reverse() | |
$command = $history | Out-GridView -Title History -PassThru | |
if ($command) | |
{ | |
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
[Microsoft.PowerShell.PSConsoleReadLine]::Insert(($command -join "`n")) | |
} | |
} | |
#region Smart Insert/Delete | |
Set-PSReadLineKeyHandler -Key '(','{','[' ` | |
-BriefDescription InsertPairedBraces ` | |
-LongDescription "Insert matching braces" ` | |
-ScriptBlock { | |
param($key, $arg) | |
$closeChar = switch ($key.KeyChar) | |
{ | |
<#case#> '(' { [char]')'; break } | |
<#case#> '{' { [char]'}'; break } | |
<#case#> '[' { [char]']'; break } | |
} | |
$selectionStart = $null | |
$selectionLength = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetSelectionState([ref]$selectionStart, [ref]$selectionLength) | |
$line = $null | |
$cursor = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) | |
if ($selectionStart -ne -1) | |
{ | |
# Text is selected, wrap it in brackets | |
[Microsoft.PowerShell.PSConsoleReadLine]::Replace($selectionStart, $selectionLength, $key.KeyChar + $line.SubString($selectionStart, $selectionLength) + $closeChar) | |
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($selectionStart + $selectionLength + 2) | |
} else { | |
# No text is selected, insert a pair | |
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("$($key.KeyChar)$closeChar") | |
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($cursor + 1) | |
} | |
} | |
Set-PSReadLineKeyHandler -Key ')',']','}' ` | |
-BriefDescription SmartCloseBraces ` | |
-LongDescription "Insert closing brace or skip" ` | |
-ScriptBlock { | |
param($key, $arg) | |
$line = $null | |
$cursor = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) | |
if ($line[$cursor] -eq $key.KeyChar) | |
{ | |
[Microsoft.PowerShell.PSConsoleReadLine]::SetCursorPosition($cursor + 1) | |
} | |
else | |
{ | |
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("$($key.KeyChar)") | |
} | |
} | |
Set-PSReadLineKeyHandler -Key Backspace ` | |
-BriefDescription SmartBackspace ` | |
-LongDescription "Delete previous character or matching quotes/parens/braces" ` | |
-ScriptBlock { | |
param($key, $arg) | |
$line = $null | |
$cursor = $null | |
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) | |
if ($cursor -gt 0) | |
{ | |
$toMatch = $null | |
if ($cursor -lt $line.Length) | |
{ | |
switch ($line[$cursor]) | |
{ | |
<#case#> '"' { $toMatch = '"'; break } | |
<#case#> "'" { $toMatch = "'"; break } | |
<#case#> ')' { $toMatch = '('; break } | |
<#case#> ']' { $toMatch = '['; break } | |
<#case#> '}' { $toMatch = '{'; break } | |
} | |
} | |
if ($toMatch -ne $null -and $line[$cursor-1] -eq $toMatch) | |
{ | |
[Microsoft.PowerShell.PSConsoleReadLine]::Delete($cursor - 1, 2) | |
} | |
else | |
{ | |
[Microsoft.PowerShell.PSConsoleReadLine]::BackwardDeleteChar($key, $arg) | |
} | |
} | |
} | |
#endregion Smart Insert/Delete | |
# PowerShell parameter completion shim for the dotnet CLI | |
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { | |
param($commandName, $wordToComplete, $cursorPosition) | |
dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object { | |
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | |
} | |
} | |
# This is an example of a macro that you might use to execute a command. | |
# This will add the command to history. | |
Set-PSReadLineKeyHandler -Key Ctrl+Shift+b ` | |
-BriefDescription BuildCurrentDirectory ` | |
-LongDescription "Build the current directory" ` | |
-ScriptBlock { | |
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("dotnet build") | |
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
} | |
Set-PSReadLineKeyHandler -Key Ctrl+Shift+t ` | |
-BriefDescription BuildCurrentDirectory ` | |
-LongDescription "Build the current directory" ` | |
-ScriptBlock { | |
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("dotnet test") | |
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment