-join (1..255 | % { "`e[48;5;$($_)m {0:00#} `e[0m" -f $_ + ($_ % 15 -eq 0 ? "`n" : " ") })
-join (1..255 | % { "`e[48;5;$($_)m {0:00#} `e[0m" -f $_ + ($_ % ($host.ui.RawUI.WindowSize.Width / 10) -eq 0 ? "`n" : " ") })
#Windows Powershell compatible version
-join (1..255 | % { "$([char]27)[48;5;$($_)m {0:00#} $([char]27)[0m" -f $_;if ($_ % ($host.ui.RawUI.WindowSize.Width / 10) -eq 0) { "`n" } else { " " } })
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
using namespace System.Management.Automation.Language | |
function table2am { | |
<# | |
format-table sugar that knows not to format if you're assigning to a variable. | |
it will automatically switch to Select-Object when assigned. | |
also tries to figure out if it's the last command in the pipeline otherwise it will default to Select-Object. | |
only implemented Property param atm, just testing it out for fun. | |
Set-Alias -Name ft -Value table -Force | |
to override default ft alias you need -Force. |
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
function colortable { | |
param( | |
[Int]$Padding = 2 | |
) | |
$ht = @{ | |
reset = "$([char]27)[0m" | |
pad = ' ' * $Padding | |
bg = "$([char]27)[48;5;" | |
# numbers + space + padding | |
len = [math]::Floor(($host.ui.RawUI.WindowSize.Width - 10) / (3 + 1 + (2 * $Padding))) |
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
function Get-TibberMonth { | |
<# | |
.DESCRIPTION | |
gets tibber usage for a month, will automatically turn any date into the first day of the month | |
and will calculate the amount of hours for that month | |
.PARAMETER Startdate | |
startdate | |
if no enddate is given it will take day 1 of the month in startdate and +1 month | |
.PARAMETER Enddate | |
enddate |
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
<# | |
yoinked and just stripped the namespace and change internal to public | |
https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/utils/FuzzyMatch.cs | |
https://www.geeksforgeeks.org/damerau-levenshtein-distance/ | |
https://yassineelkhal.medium.com/the-complete-guide-to-string-similarity-algorithms-1290ad07c6b7 | |
#> | |
Add-Type -TypeDefinition @' | |
// Copyright (c) Microsoft Corporation. | |
// Licensed under the MIT License. |
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
function ConvertTo-TableFormat { | |
<# | |
.SYNOPSIS | |
Rebuild an object based on the Format Data for the object. | |
.DESCRIPTION | |
Allows an object to be rebuilt based on the view data for the object. Uses Select-Object to create a new PSCustomObject. | |
#> | |
[CmdletBinding()] | |
param ( |
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
function Add-ClipboardProtocolHandler { | |
# clipboard:// | |
$custom = Get-Command "$env:temp\customclip.exe" -CommandType Application -ErrorAction 'Stop' | |
$uri = 'clipboard' | |
if (!(Test-Path "HKCU:\Software\Classes\$uri")) { | |
New-Item "HKCU:\Software\Classes\$uri" | |
} | |
Set-ItemProperty "HKCU:\Software\Classes\$uri" '(Default)' "URL:$uri Protocol" | |
Set-ItemProperty "HKCU:\Software\Classes\$uri" 'URL Protocol' '' | |
if (!(Test-Path "HKCU:\Software\Classes\$uri\shell")) { |
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
function Set-DemoPrompt { | |
<# | |
.SYNOPSIS | |
Creates a simple prompt with WT highlighting using a temporary module. | |
minor trickery with setting an alias for prompt so we can easily restore old prompt on module removal. | |
.NOTES | |
it adds terminal prompt markings for WT Preview. | |
see links below for more info | |
.LINK | |
https://learn.microsoft.com/en-us/windows/terminal/tutorials/shell-integration#powershell-pwshexe/ |
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
function Enable-DebugSpectre { | |
[cmdletbinding()] | |
param() | |
$moduleName = 'PwshSpectreConsole' | |
$module = Get-Module -Name $ModuleName | |
if (-Not $Module) { | |
$Module = Import-Module $ModuleName -PassThru | |
} | |
$new = { | |
param( |
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
Update-TypeData -TypeName '_RegexAnsi' -MemberType ScriptMethod -MemberName ToString -Force -Value { | |
return ($this.Value ? $this.value : $this.Text) | |
} | |
Update-TypeData -TypeName 'System.Management.Automation.Internal.StringDecorated' -MemberType ScriptMethod -MemberName ToString -Force -Value { | |
return $this.IsDecorated | |
} | |
function Get-AnsiEscape { | |
<# | |
.DESCRIPTION | |
Get-AnsiEscape can be used to strip, escape, or regex VT codes from a string. |