Created
October 20, 2021 01:53
-
-
Save fredimachado/be845ac2b26e9f2d5d3815c6d6e6e7e6 to your computer and use it in GitHub Desktop.
My Microsoft.PowerShell_profile.ps1
This file contains 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
$global:DefaultUser = 'Fredi' | |
if ($host.Name -eq 'ConsoleHost') | |
{ | |
Import-Module PSReadLine | |
} | |
Import-Module Terminal-Icons | |
Import-Module oh-my-posh | |
Set-PoshPrompt -Theme ~/myparadox.omp.json | |
Set-PSReadLineOption -PredictionSource History | |
Set-PSReadLineOption -PredictionViewStyle ListView | |
Set-PSReadLineOption -EditMode Windows | |
function Get-FolderSize($path) { | |
Get-ChildItem -Path $path -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum | Select-Object Sum, Count | |
} | |
function Remove-BinObjVsFolders($path) { | |
Get-FolderSize $path | |
Get-ChildItem $path -Include bin,obj,.vs -Recurse -Force -Directory | ForEach-Object ($_) { Remove-Item $_.FullName -Force -Recurse } | |
Get-FolderSize $path | |
} | |
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")) | |
} | |
} | |
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+r ` | |
-BriefDescription RunCurrentDirectory ` | |
-LongDescription "Run the current directory" ` | |
-ScriptBlock { | |
[Microsoft.PowerShell.PSConsoleReadLine]::RevertLine() | |
[Microsoft.PowerShell.PSConsoleReadLine]::Insert("dotnet run") | |
[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