Skip to content

Instantly share code, notes, and snippets.

View Jaykul's full-sized avatar
😀
Learning

Joel Bennett Jaykul

😀
Learning
View GitHub Profile
@Jaykul
Jaykul / GraphingWithSixel.md
Created March 22, 2025 06:25
We're all going to be graphing in terminals with sixels...

The basic idea here is that anything that can produce an image can embed it's output in the terminal now...

image

@Jaykul
Jaykul / About Querying Users From Background Scripts.md
Last active January 25, 2025 22:54
This is how you can query the active user from a script running under other credentials

Someone on the PowerShell Discord asked about sending a message box to the current user on a computer.

This method should work to query the user for a choice (with an optional timeout) or simply notify them of something, whether the script is being run by the user or by an administrator in a remote PowerShell session, or from system, etc.

It's not thoroughly tested (as with most of what I put on gists), but it does work.

Here's some examples:

Show-RemoteDesktopMessage -Title "Test Message" -Message "This is a test message."
@Jaykul
Jaykul / Format-ScriptFile.ps1
Last active February 6, 2025 07:59
When you need to reformat a bunch of PowerShell scripts
<#
.SYNOPSIS
Formats a script file using PSScriptAnalyzer
.DESCRIPTION
Formats a script file using PSScriptAnalyzer and some hard-coded rules.
There are many formatters, but this one is mine.
.EXAMPLE
Get-ChildItem -Recurse -Filter *.ps1 | Format-ScriptFile
#>
[CmdletBinding()]
@Jaykul
Jaykul / Test-Transcribing.ps1
Created November 1, 2024 21:01
Is Start-Transcription running
function Test-Transcribing {
[CmdletBinding()]
param()
$Host.UI.GetType().GetProperty("IsTranscribing",[Reflection.BindingFlags]"NonPublic,Instance").GetValue($Host.UI)
}
@Jaykul
Jaykul / WrapString.ps1
Created October 5, 2024 17:35
String Wrapping. Again.
# Borrowed this one from https://github.com/chalk/ansi-regex
$script:AnsiPattern = "[\u001b\u009b][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?(?:\u001b\u005c|\u0007))|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))"
$script:AnsiRegex = [Regex]::new($AnsiPattern, "Compiled");
function MeasureString {
[CmdletBinding()]
param(
[string]$InputObject
)
$AnsiRegex.Replace($InputObject, '').Length
@Jaykul
Jaykul / gcixel.ps1
Created September 1, 2024 04:55
ImageMagick and Sixels -- this is not fast, but it works even across ssh
<#
.SYNOPSIS
gcixels is like gci, but with sixels...
.DESCRIPTION
Shows thumbnails of images with titles, directly in terminal.
However, it's done with ImageMagick montage, so it's awfully slow.
Just sharing it for your inspiration.
.NOTES
Requires ImageMagick and a Sixel terminal (like Windows Terminal 1.22+ or WezTerm)
#>
@Jaykul
Jaykul / PowerShellConfig.psm1
Last active September 11, 2024 02:31
Functions for powershell.config.json
#requires -Modules Metadata
function Get-PowerShellConfig {
<#
.SYNOPSIS
Get the PowerShell.config.json as a hashtable
.EXAMPLE
Get-PowerShellConfig
Returns the user's PowerShell Config (usually just what experiments you've enabled)
.EXAMPLE
@Jaykul
Jaykul / Start-Application.ps1
Created August 16, 2024 05:40
So I remember how to find an Appx application by (partial) name
function Start-Application {
param($Name)
if (!($Command = @(Get-Command $Name -CommandType Application -ErrorAction Ignore)[0])) {
$Command = foreach ($Package in Get-AppxPackage *$Name*) {
($Package | Get-AppxPackageManifest).Package.Applications.Application.Executable | % {
Join-Path -Path $Package.InstallLocation -ChildPath $_
} | Get-Command
}
}
& $Command
@Jaykul
Jaykul / Convert-RTTTL.ps1
Last active August 9, 2024 05:24
Convert Nokia RTTL to VT256 DEC PS (PlaySound) escape sequences
function Convert-RTTTL {
<#
.SYNOPSIS
Convert Nokia RTTL to VT256 DEC PS (PlaySound) escape sequences for Windows Terminal, for instance.
.EXAMPLE
Convert-RTTTL 'Mario World Theme:d=4,o=5,b=125:a,8f.,16c,16d,16f,16p,f,16d,16c,16p,16f,16p,16f,16p,8c6,8a.,g,16c,a,8f.,16c,16d,16f,16p,f,16d,16c,16p,16f,16p,16a#,16a,16g,2f,16P,8a.,8f.,8c,8a.,f,16g#,16f,16c,16p,8g#.,2g,8a.,8f.,8c,8a.,f,16g#,16f,8c,2c6' -InformationAction Continue
Plays the Mario World Theme song (and show the name in the console).
.EXAMPLE
Convert-RTTTL 'HauntHouse: d=4,o=6,b=108: 2a5, 2e, 2d#, 2b5, 2a5, 2c, 2d, 2a#5, 2e., e, 1f5, 1a5, 1d#, 2e., d, 2c., b5, 1a5, 1p, 2a5, 2e, 2d#, 2b5, 2a5, 2c, 2d, 2a#5, 2e., e, 1f5, 1a5, 1d#, 2e., d, 2c., b5, 1a5' | Set-Clipboard

This is barely worth sharing, but you can, for instance, get everything pinned to the taskbar, and unpin it from the start menu

Get-Application -PinnedToTaskbar | UnpinStart

Huge Caveat: I haven't figured this all out.

  1. I can't figure out a way to get the order of the taskbar items...
  2. Many items don't have the "pin to taskbar" verb when called this way (I don't know why) and you have to do something ridiculous like making a shortcut to them first (thus, the task bar folder) and then pin that.