Last active
January 29, 2025 00:03
-
-
Save rkeithhill/e85072f4dd621f1d202fd10b92a4b711 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
if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) { | |
Set-Alias nano 'C:\Program Files\Git\usr\bin\nano.exe' | |
Set-Alias vim 'C:\Program Files\Git\usr\bin\vim.exe' | |
} | |
# Edition/platform specific configuration | |
if ($IsWindows) { | |
$env:PAGER = 'less -Ps"Page %db?B of %D:.\. Press h for help or Q to quit\."' | |
if ($PSVersionTable.PSEdition -eq 'Desktop') { | |
$PSDefaultParameterValues['Get-Help:Full'] = $true | |
$PSDefaultParameterValues['Install-Module:Scope'] = 'CurrentUser' | |
} | |
} | |
$enableProfiling = $false | |
function LogExecutionTime([scriptblock]$Scriptblock, [string]$Message) { | |
if ($enableProfiling) { | |
if (!$script:sw) { | |
$script:sw = [System.Diagnostics.Stopwatch]::StartNew() | |
} | |
else { | |
$script:sw.Restart() | |
} | |
} | |
&$Scriptblock | |
if ($enableProfiling) { | |
$script:sw.Stop() | |
Write-Warning "$Message took: $($script:sw.ElapsedMilliseconds) ms" | |
} | |
} | |
# Configure the built-in PSReadLine module | |
LogExecutionTime { . $PSScriptRoot\PSReadLine_config.ps1 } "Configuring PSReadLine" | |
# Import and configure posh-git | |
LogExecutionTime { . $PSScriptRoot\posh-git_config.ps1 } "Importing and configuring posh-git" | |
# PowerShell parameter completion shim for the dotnet CLI | |
LogExecutionTime { | |
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { | |
param($wordToComplete, $comamndAst, $cursorPosition) | |
$global:wordTC = $wordToComplete | |
$global:cmdAst = $comamndAst | |
$global:cmdPos = $cursorPosition | |
# Write-Warning "wordToComplete is $wordToComplete, comamndAst is $($comamndAst | fl | out-string -stream), pos i $cursorPosition" | |
dotnet complete --position $cursorPosition $comamndAst | ForEach-Object { | |
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | |
} | |
} | |
} "Register argument completer for dotnet" | |
<# | |
.SYNOPSIS | |
Resets the current console's size and optionally buffer size. | |
.DESCRIPTION | |
This command manipulates the $host.UI.RawUI.WindowSize and | |
$host.UI.RawUI.BufferSize structs to set the desired sizes. | |
.EXAMPLE | |
PS> Reset-ConsoleSize | |
Resets to a default size of 120x50 unless the current display | |
has a $host.UI.RawUI.MaxPhysicalWindowSize that is smaller in | |
one or both dimensions. In this case, the size is limited to the | |
max size in that dimension. | |
.EXAMPLE | |
PS> Reset-ConsoleSize -Width 150 | |
Resets to a default size of 150x50 and bumps the buffer width to 150. | |
.EXAMPLE | |
PS> Reset-ConsoleSize -Width 80 -Height 40 -BufferWidth 240 | |
Resets to a default size of 80x40 and bumps the buffer width to 240. | |
#> | |
function Reset-ConsoleSize { | |
param( | |
# The desired console window width. The default value is 120 unless the | |
# maximum physical window width is less than 120. In the case, the default | |
# value will be the maximum physical window width. | |
[Parameter()] | |
[int] | |
$Width = $([Math]::Min(120, $host.UI.RawUI.MaxPhysicalWindowSize.Width)), | |
# The desired console window height. The default value is 50 unless the | |
# maximum physical window height is less than 50. In the case, the default | |
# value will be the maximum physical window height. | |
[Parameter()] | |
[int] | |
$Height = $([Math]::Min(50, $host.UI.RawUI.MaxPhysicalWindowSize.Height)), | |
# The desired console buffer width. The default value is to use the window width | |
# as the buffer width. Note: the buffer width must be greater than or equal to the | |
# window width. | |
[Parameter()] | |
[int] | |
$BufferWidth, | |
# The desired console buffer height. The default value is 9999. Note: the buffer | |
# height must be greater than or equal to the window height. | |
[Parameter()] | |
[int] | |
$BufferHeight = 9999 | |
) | |
if (!$BufferWidth) {$BufferWidth = $Width} | |
if (($Width -gt $BufferWidth) -or ($Height -gt $BufferHeight)) { | |
throw "Window size cannot be greater than the buffer size in either dimension." | |
} | |
$curBufSize = $host.UI.RawUI.BufferSize | |
$curWinSize = $host.UI.RawUI.WindowSize | |
if ($curBufSize.Width -lt $Width) { | |
$host.UI.RawUI.BufferSize = [System.Management.Automation.Host.Size]::new($BufferWidth, $curBufSize.Height) | |
$host.UI.RawUI.WindowSize = [System.Management.Automation.Host.Size]::new($Width, $curWinSize.Height) | |
} | |
else { | |
$host.UI.RawUI.WindowSize = [System.Management.Automation.Host.Size]::new($Width, $curWinSize.Height) | |
$host.UI.RawUI.BufferSize = [System.Management.Automation.Host.Size]::new($BufferWidth, $curBufSize.Height) | |
} | |
$curBufSize = $host.UI.RawUI.BufferSize | |
$curWinSize = $host.UI.RawUI.WindowSize | |
if ($curBufSize.Height -lt $Height) { | |
$host.UI.RawUI.BufferSize = [System.Management.Automation.Host.Size]::new($curBufSize.Width, $BufferHeight) | |
$host.UI.RawUI.WindowSize = [System.Management.Automation.Host.Size]::new($curWinSize.Width, $Height) | |
} | |
else { | |
$host.UI.RawUI.WindowSize = [System.Management.Automation.Host.Size]::new($curWinSize.Width, $Height) | |
$host.UI.RawUI.BufferSize = [System.Management.Automation.Host.Size]::new($curBufSize.Width, $BufferHeight) | |
} | |
} | |
#Register-EngineEvent -SourceIdentifier PowerShell.Exiting -SupportEvent -Action { | |
# Write-Host "Saving command history..." | |
# $historyDir = Join-Path (Split-Path $profile) History | |
# if (!(Test-Path $historyDir)) { | |
# md $historyDir | |
# } | |
# $historyPath = Join-Path $historyDir "history_$(Get-Date -f yyyyMMdd.HHmmss)_${pid}.clixml" | |
# Get-History | Export-Clixml $historyPath -Encoding Utf8 | |
#} | |
# Set-Alias srh Search-History | |
# function Search-History($Pattern, [switch]$All) { | |
# if ($All) { | |
# $historyDir = Join-Path (Split-Path $profile) History | |
# $historyFiles = Get-ChildItem $historyDir -File | Sort-Object LastWriteTime -Desc | |
# foreach ($file in $historyFiles) { | |
# $hist = Import-Clixml $file.FullName | |
# $hist | Where-Object {$_.CommandLine -match $Pattern} | |
# } | |
# } | |
# else { | |
# Get-History -Count ((Get-History -count 1).Id) | Where-Object {$_.CommandLine -match $Pattern} | |
# } | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment