Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Last active December 2, 2022 08:55
Show Gist options
  • Save Jaykul/bf5688ad593584cc440c15dafb630563 to your computer and use it in GitHub Desktop.
Save Jaykul/bf5688ad593584cc440c15dafb630563 to your computer and use it in GitHub Desktop.
Doing demos with just PSReadLine
function Start-Demo {
[CmdletBinding()]
param(
# A history file with a command on each line (or using ` as a line-continuation character)
[Parameter(Mandatory)]
[Alias("PSPath")]
[string]$Path
)
[Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()
foreach($command in (Get-Content $Path -Raw) -split '(?<!`)\r\n' -replace '`\r\n',"`r`n") {
[Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($command)
}
Write-Host "Press Ctrl+Home to go to the start of the demo, and Ctrl+Enter to run each line" -Foreground Yellow
Set-PSReadLineKeyHandler Ctrl+Home BeginningOfHistory
Set-PSReadLineKeyHandler Ctrl+Enter AcceptAndGetNext
}
Import-Module Information
Set-InfoTemplate '`e[38;5;8m{PSComputerName} `e[38;5;1m{ElapsedTime:mm:ss.fff} {Indent}`e[38;5;6m{Message}`e[39m'
function Get-Example {`
[CmdletBinding()]param()`
Get-ChildItem -File | Where Length -lt 10kb | Format-Table`
}
Get-Example -infa Continue
Get-Command Get-ChildItem, Where-Object | New-LoggingCommand
Get-Example -infa Continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment