Skip to content

Instantly share code, notes, and snippets.

View bielawb's full-sized avatar

Bartek Bielawski bielawb

View GitHub Profile
@bielawb
bielawb / New-ModuleClassInstance.ps1
Created December 30, 2016 07:27
Work-around for the fact that `using module` is not very flexible.
param (
[string]$Path,
[string]$ClassName
)
$scriptBody = @'
using module {0}
'@ -f $Path
$script = [scriptblock]::Create($scriptBody)
@bielawb
bielawb / Get-ModuleDefinedClass.ps1
Last active December 30, 2016 08:33
Just an attempt to get info about classes defined by a given module.
[CmdletBinding()]
[OutputType([hashtable])]
param (
[string]$Path,
[string]$ClassName = '*'
)
$moduleBase = Split-Path -Path $Path -Parent
Write-Verbose "Module name - $fileName"
@bielawb
bielawb / GitAliasesHelper.ps1
Created November 10, 2017 09:45
Snippet that can be added to the profile to turn git aliases into PowerShell commands. Note: this solution doesn't support parameters.
$gitAliases = (git config --global -l).Where{ $_ -match '^alias\.'}.ForEach{$_ -replace '^alias\.(\w+).*', '$1'}
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param ($name, $eventArgs)
if ($name -in $gitAliases) {
$alias = $name
} elseif ($aliases = $gitAliases -match [regex]::Escape($name)) {
$alias = $aliases | Sort-Object -Property Length | Select-Object -First 1
}
@bielawb
bielawb / invoke-insult.ps1
Created November 17, 2017 20:36
If you want your PowerShell to insult you when you run wrong command...
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
param ($name, $eventArgs)
@(
"Boooo!"
"Don't you know anything?"
"RTFM!"
"Hahaha, n00b!"
"Wow! That was impressively wrong!"
"He said: $name :D"
"What are you doing??"
@bielawb
bielawb / FixDolarUnderscoreUnderscore.ps1
Created September 7, 2022 09:54
Fix $__ in PS7 with PSReadLine/ replacing it with Get-History call.
Set-PSReadlineKeyHandler -Chord Spacebar -ScriptBlock {
param ($key, $arg)
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState(
[ref]$line, [ref]$cursor
)
if ($cursor -lt 3) {
return