The rest of the code is here: Write.Html.pq
// aliases
Write.Format = String.Write.Format,
Write.Element = Write.Html.Element,
Write.Key = Write.Html.KeyValue,
Tag = Write.Html.Element,
The rest of the code is here: Write.Html.pq
// aliases
Write.Format = String.Write.Format,
Write.Element = Write.Html.Element,
Write.Key = Write.Html.KeyValue,
Tag = Write.Html.Element,
using namespace System.Collections.Generic | |
Import-module Pansies | |
function Dotfiles.Select-Some { | |
<# | |
.SYNOPSIS | |
select 1 item, 5, or a specific count. | |
.NOTES | |
- [ ] future: rewrite using steppable pipeline for an earlier exit | |
.EXAMPLE |
function ConvertTo-MarkdownTable { | |
<# | |
.DESCRIPTION | |
Convert an object to a markdown table. | |
.PARAMETER InputObject | |
The object to convert to a markdown table. | |
.PARAMETER Property | |
The properties to display in the table. |
using namespace System.Collections.Generic | |
using namespace Microsoft.PowerShell.Commands.Internal.Format | |
#Inspired by: https://gist.github.com/aaroncalderon/09a2833831c0f3a3bb57fe2224963942 | |
<# | |
.Synopsis | |
Converts PowerShell Objects or Format-Table output to Markdown | |
#> | |
Function ConvertTo-Markdown { | |
[CmdletBinding()] |
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. |
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/ |
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")) { |
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 ( |
<# | |
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. |
-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 { " " } })