Last active
December 2, 2022 08:55
-
-
Save Jaykul/bf5688ad593584cc440c15dafb630563 to your computer and use it in GitHub Desktop.
Doing demos with just PSReadLine
This file contains 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 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 | |
} |
This file contains 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
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