Skip to content

Instantly share code, notes, and snippets.

@FriedrichWeinmann
Created October 27, 2025 14:04
Show Gist options
  • Save FriedrichWeinmann/11322cf9959ea28ba6792a94581ea1c1 to your computer and use it in GitHub Desktop.
Save FriedrichWeinmann/11322cf9959ea28ba6792a94581ea1c1 to your computer and use it in GitHub Desktop.
Make items in a list easily, manually accessible with shortcuts, such as "L0", "L1", "L2", ...
function Register-ListReader {
[CmdletBinding()]
param (
$List,
$Property
)
Register-ListHandler
$global:__LR_Config = @{
List = $List
Property = $Property
}
}
function Get-ListValue {
[CmdletBinding()]
param (
[int]
$Value = $global:__LR_Config.Index
)
if (-not $global:__LR_Config.List) { return }
$item = $global:__LR_Config.List[$Value]
if ($global:__LR_Config.Property) { $item.$($global:__LR_Config.Property) }
else { $item }
}
function Register-ListHandler {
[CmdletBinding()]
param ()
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
Param ($Name, $EventArgs)
if ($Name.Trim('.\') -notmatch '^L(?<id>\d+)$') { return }
$global:__LR_Config.Index = $matches.id
$EventArgs.Command = Get-Command Get-ListValue
$EventArgs.StopSearch = $true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment