From 6c870eb8dc7fb4d03d1a2e4cd17ba52b9405180d Mon Sep 17 00:00:00 2001 From: mdgrs <81177095+mdgrs-mei@users.noreply.github.com> Date: Sat, 10 Jan 2026 10:44:00 +0900 Subject: [PATCH 1/4] Add ValueFromPipeline to Set-PSRunDefault* functions --- .../Public/Set-PSRunDefaultEditorScript.ps1 | 4 ++-- .../Public/Set-PSRunDefaultSelectorOption.ps1 | 4 ++-- .../Public/Set-PSRunDefaultEditorScript.Tests.ps1 | 14 ++++++++++++++ .../Set-PSRunDefaultSelectorOption.Tests.ps1 | 7 +++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/module/PowerShellRun/Public/Set-PSRunDefaultEditorScript.ps1 b/module/PowerShellRun/Public/Set-PSRunDefaultEditorScript.ps1 index 8a718a0..6aaeb98 100644 --- a/module/PowerShellRun/Public/Set-PSRunDefaultEditorScript.ps1 +++ b/module/PowerShellRun/Public/Set-PSRunDefaultEditorScript.ps1 @@ -15,7 +15,7 @@ The following script is used by default: } .INPUTS -None. +The ScriptBlock parameter. .OUTPUTS None. @@ -30,7 +30,7 @@ function Set-PSRunDefaultEditorScript { [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [ScriptBlock]$ScriptBlock ) diff --git a/module/PowerShellRun/Public/Set-PSRunDefaultSelectorOption.ps1 b/module/PowerShellRun/Public/Set-PSRunDefaultSelectorOption.ps1 index 847b04d..5787313 100644 --- a/module/PowerShellRun/Public/Set-PSRunDefaultSelectorOption.ps1 +++ b/module/PowerShellRun/Public/Set-PSRunDefaultSelectorOption.ps1 @@ -12,7 +12,7 @@ Use this command to see what properties are available: [PowerShellRun.SelectorOption]::new() | Get-Member -MemberType Properties .INPUTS -None. +The Option parameter. .OUTPUTS None. @@ -26,7 +26,7 @@ function Set-PSRunDefaultSelectorOption { [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [PowerShellRun.SelectorOption]$Option ) diff --git a/tests/Public/Set-PSRunDefaultEditorScript.Tests.ps1 b/tests/Public/Set-PSRunDefaultEditorScript.Tests.ps1 index a134d63..bcd9f4c 100644 --- a/tests/Public/Set-PSRunDefaultEditorScript.Tests.ps1 +++ b/tests/Public/Set-PSRunDefaultEditorScript.Tests.ps1 @@ -17,6 +17,20 @@ } } + It 'should accept a pipeline input' { + $script = { + param($path) + & notepad.exe $path + } + + $script | Set-PSRunDefaultEditorScript + + InModuleScope 'PowerShellRun' -ArgumentList $script { + param($script) + $script:globalStore.defaultEditorScript | Should -Be $script + } + } + AfterEach { Remove-Module PowerShellRun -Force } diff --git a/tests/Public/Set-PSRunDefaultSelectorOption.Tests.ps1 b/tests/Public/Set-PSRunDefaultSelectorOption.Tests.ps1 index d1d2636..bf9ffa8 100644 --- a/tests/Public/Set-PSRunDefaultSelectorOption.Tests.ps1 +++ b/tests/Public/Set-PSRunDefaultSelectorOption.Tests.ps1 @@ -11,6 +11,13 @@ $match | Should -Be 'a' } + It 'should accept a pipeline input' { + $option.AutoReturnBestMatch = $true + $option | Set-PSRunDefaultSelectorOption + $match = 'a', 'b' | Invoke-PSRunSelector + $match | Should -Be 'a' + } + AfterEach { Remove-Module PowerShellRun -Force } From ff60177a85c91b34f81406620f53c4a6e7af4c2c Mon Sep 17 00:00:00 2001 From: mdgrs <81177095+mdgrs-mei@users.noreply.github.com> Date: Sun, 11 Jan 2026 14:36:48 +0900 Subject: [PATCH 2/4] Add ValueFromPipeline to Enable-PSRunEntry --- .../Public/Enable-PSRunEntry.ps1 | 35 ++++++++++++++----- tests/Public/Enable-PSRunEntry.Tests.ps1 | 5 ++- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/module/PowerShellRun/Public/Enable-PSRunEntry.ps1 b/module/PowerShellRun/Public/Enable-PSRunEntry.ps1 index 2e56f12..3f4708d 100644 --- a/module/PowerShellRun/Public/Enable-PSRunEntry.ps1 +++ b/module/PowerShellRun/Public/Enable-PSRunEntry.ps1 @@ -10,7 +10,7 @@ By default, all categories are enabled. Specifies a category or an array of categories to enable. .INPUTS -None. +The Category parameter. .OUTPUTS None. @@ -24,17 +24,36 @@ Enable-PSRunEntry -Category Application, Function, Utility function Enable-PSRunEntry { [CmdletBinding()] param ( + [Parameter(ValueFromPipeline = $true)] [ValidateSet('All', 'Application', 'Executable', 'Function', 'Utility', 'Favorite', 'Script', 'EntryGroup')] [String[]]$Category = 'All' ) - if ($script:globalStore.IsEntriesInitialized()) { - Write-Error -Message 'Entries already initialized. This function must be called only once.' -Category InvalidOperation - return - } + begin { + if ($script:globalStore.IsEntriesInitialized()) { + Write-Error -Message 'Entries already initialized. This function must be called only once.' -Category InvalidOperation + return + } - if ($Category -contains 'All') { - $Category = $script:globalStore.allCategoryNames + $categories = [System.Collections.Generic.List[String]]::new() + } + process { + if ($script:globalStore.IsEntriesInitialized()) { + return + } + + foreach ($c in $Category) { + $categories.Add($c) + } + } + end { + if ($script:globalStore.IsEntriesInitialized()) { + return + } + + if ($categories -contains 'All') { + $categories = $script:globalStore.allCategoryNames + } + $script:globalStore.InitializeEntries($categories) } - $script:globalStore.InitializeEntries($Category) } diff --git a/tests/Public/Enable-PSRunEntry.Tests.ps1 b/tests/Public/Enable-PSRunEntry.Tests.ps1 index 1533f19..6fa950a 100644 --- a/tests/Public/Enable-PSRunEntry.Tests.ps1 +++ b/tests/Public/Enable-PSRunEntry.Tests.ps1 @@ -11,12 +11,15 @@ Enable-PSRunEntry Function, Utility, Favorite } + It 'should accept pipeline inputs' { + 'function', 'Utility', 'Favorite' | Enable-PSRunEntry + } + It 'should throw if called twice' { Enable-PSRunEntry { Enable-PSRunEntry -ErrorAction Stop } | Should -Throw } - AfterEach { Remove-Module PowerShellRun -Force } From a7c31bc21e2d25202f278d63eaad7ba2a17e11a0 Mon Sep 17 00:00:00 2001 From: mdgrs <81177095+mdgrs-mei@users.noreply.github.com> Date: Sun, 11 Jan 2026 15:08:52 +0900 Subject: [PATCH 3/4] Add ValueFromPipeline to Add-PSRun* functions --- module/PowerShellRun/Public/Add-PSRunEntryGroup.ps1 | 4 ++-- module/PowerShellRun/Public/Add-PSRunFavoriteFile.ps1 | 4 ++-- .../PowerShellRun/Public/Add-PSRunFavoriteFolder.ps1 | 4 ++-- module/PowerShellRun/Public/Add-PSRunFunction.ps1 | 4 ++-- module/PowerShellRun/Public/Add-PSRunScriptBlock.ps1 | 4 ++-- module/PowerShellRun/Public/Add-PSRunScriptFile.ps1 | 4 ++-- tests/Public/Add-PSRunEntryGroup.Tests.ps1 | 9 +++++++++ tests/Public/Add-PSRunFavoriteFile.Tests.ps1 | 9 +++++++++ tests/Public/Add-PSRunFavoriteFolder.Tests.ps1 | 9 +++++++++ tests/Public/Add-PSRunFunction.Tests.ps1 | 11 +++++++++++ tests/Public/Add-PSRunScriptBlock.Tests.ps1 | 9 +++++++++ tests/Public/Add-PSRunScriptFile.Tests.ps1 | 9 +++++++++ 12 files changed, 68 insertions(+), 12 deletions(-) diff --git a/module/PowerShellRun/Public/Add-PSRunEntryGroup.ps1 b/module/PowerShellRun/Public/Add-PSRunEntryGroup.ps1 index 0fc8b33..46f09ef 100644 --- a/module/PowerShellRun/Public/Add-PSRunEntryGroup.ps1 +++ b/module/PowerShellRun/Public/Add-PSRunEntryGroup.ps1 @@ -28,7 +28,7 @@ The parent entry group object where this new entry group is added. Returns the added entry group if specified. .INPUTS -None. +The Name parameter. .OUTPUTS An object that represents an entry group if PassThru is specified. None otherwise. @@ -46,7 +46,7 @@ function Add-PSRunEntryGroup { [Parameter(ValueFromPipelineByPropertyName = $true)] [String]$Icon, - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [String]$Name, [Parameter(ValueFromPipelineByPropertyName = $true)] diff --git a/module/PowerShellRun/Public/Add-PSRunFavoriteFile.ps1 b/module/PowerShellRun/Public/Add-PSRunFavoriteFile.ps1 index bf3066f..28831e6 100644 --- a/module/PowerShellRun/Public/Add-PSRunFavoriteFile.ps1 +++ b/module/PowerShellRun/Public/Add-PSRunFavoriteFile.ps1 @@ -24,7 +24,7 @@ The custom preview string. The parent entry group object where this new entry is added. .INPUTS -None. +The Path parameter. .OUTPUTS None. @@ -38,7 +38,7 @@ Add-PSRunFavoriteFile -Path 'D:\PowerShellRun\Build.ps1' -Icon '๐Ÿงช' -Name 'Bui function Add-PSRunFavoriteFile { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [String]$Path, [Parameter(ValueFromPipelineByPropertyName = $true)] diff --git a/module/PowerShellRun/Public/Add-PSRunFavoriteFolder.ps1 b/module/PowerShellRun/Public/Add-PSRunFavoriteFolder.ps1 index c3276de..50daf94 100644 --- a/module/PowerShellRun/Public/Add-PSRunFavoriteFolder.ps1 +++ b/module/PowerShellRun/Public/Add-PSRunFavoriteFolder.ps1 @@ -24,7 +24,7 @@ The custom preview string. The parent entry group object where this new entry is added. .INPUTS -None. +The Path parameter. .OUTPUTS None. @@ -38,7 +38,7 @@ Add-PSRunFavoriteFolder -Path 'D:/Download' -Icon '๐ŸŒ' function Add-PSRunFavoriteFolder { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [String]$Path, [Parameter(ValueFromPipelineByPropertyName = $true)] diff --git a/module/PowerShellRun/Public/Add-PSRunFunction.ps1 b/module/PowerShellRun/Public/Add-PSRunFunction.ps1 index 9d56fec..cd2e9ed 100644 --- a/module/PowerShellRun/Public/Add-PSRunFunction.ps1 +++ b/module/PowerShellRun/Public/Add-PSRunFunction.ps1 @@ -25,7 +25,7 @@ The custom preview string. The parent entry group object where this new entry is added. .INPUTS -None. +The FunctionName parameter. .OUTPUTS None. @@ -41,7 +41,7 @@ Add-PSRunFunction -FunctionName TestFunction -Icon '๐Ÿ' -Name 'Test Function' function Add-PSRunFunction { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [String]$FunctionName, [Parameter(ValueFromPipelineByPropertyName = $true)] diff --git a/module/PowerShellRun/Public/Add-PSRunScriptBlock.ps1 b/module/PowerShellRun/Public/Add-PSRunScriptBlock.ps1 index 28b5d6a..35c58a0 100644 --- a/module/PowerShellRun/Public/Add-PSRunScriptBlock.ps1 +++ b/module/PowerShellRun/Public/Add-PSRunScriptBlock.ps1 @@ -27,7 +27,7 @@ The custom preview string. The definition of the ScriptBlock is used by default. The parent entry group object where this new entry is added. .INPUTS -None. +The ScriptBlock parameter. .OUTPUTS None. @@ -43,7 +43,7 @@ Add-PSRunScriptBlock -Icon '๐Ÿฅ' -Name 'GitPullRebase' -Description 'git pull w function Add-PSRunScriptBlock { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [ScriptBlock]$ScriptBlock, [Parameter(ValueFromPipelineByPropertyName = $true)] diff --git a/module/PowerShellRun/Public/Add-PSRunScriptFile.ps1 b/module/PowerShellRun/Public/Add-PSRunScriptFile.ps1 index 1051d89..2851c98 100644 --- a/module/PowerShellRun/Public/Add-PSRunScriptFile.ps1 +++ b/module/PowerShellRun/Public/Add-PSRunScriptFile.ps1 @@ -27,7 +27,7 @@ The custom preview string. The content of the script file is used by default. The parent entry group object where this new entry is added. .INPUTS -None. +The Path parameter. .OUTPUTS None. @@ -41,7 +41,7 @@ Add-PSRunScriptFile -Path 'D:\PowerShellRun\Build.ps1' -Icon '๐Ÿงช' -Name 'Build function Add-PSRunScriptFile { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [String]$Path, [Parameter(ValueFromPipelineByPropertyName = $true)] diff --git a/tests/Public/Add-PSRunEntryGroup.Tests.ps1 b/tests/Public/Add-PSRunEntryGroup.Tests.ps1 index 0e62e25..594c70b 100644 --- a/tests/Public/Add-PSRunEntryGroup.Tests.ps1 +++ b/tests/Public/Add-PSRunEntryGroup.Tests.ps1 @@ -48,6 +48,15 @@ $group | Should -Not -BeNullOrEmpty } + It 'should accept a pipeline input' { + Enable-PSRunEntry -Category EntryGroup + 'Custom Name' | Add-PSRunEntryGroup + InModuleScope 'PowerShellRun' { + $registry = $script:globalStore.GetRegistry('EntryGroupRegistry') + $registry.entries.Count | Should -Be 1 + } + } + AfterEach { Remove-Module PowerShellRun -Force } diff --git a/tests/Public/Add-PSRunFavoriteFile.Tests.ps1 b/tests/Public/Add-PSRunFavoriteFile.Tests.ps1 index 44c49d8..30c68c6 100644 --- a/tests/Public/Add-PSRunFavoriteFile.Tests.ps1 +++ b/tests/Public/Add-PSRunFavoriteFile.Tests.ps1 @@ -29,6 +29,15 @@ } } + It 'should accept a pipeline input' { + Enable-PSRunEntry -Category Favorite + 'C:/folder/test.txt' | Add-PSRunFavoriteFile + InModuleScope 'PowerShellRun' { + $registry = $script:globalStore.GetRegistry('FileSystemRegistry') + $registry.favoritesEntries.Count | Should -Be 1 + } + } + AfterEach { Remove-Module PowerShellRun -Force } diff --git a/tests/Public/Add-PSRunFavoriteFolder.Tests.ps1 b/tests/Public/Add-PSRunFavoriteFolder.Tests.ps1 index 82ffb61..5f05518 100644 --- a/tests/Public/Add-PSRunFavoriteFolder.Tests.ps1 +++ b/tests/Public/Add-PSRunFavoriteFolder.Tests.ps1 @@ -29,6 +29,15 @@ } } + It 'should accept a pipeline input' { + Enable-PSRunEntry -Category Favorite + 'C:/folder' | Add-PSRunFavoriteFolder + InModuleScope 'PowerShellRun' { + $registry = $script:globalStore.GetRegistry('FileSystemRegistry') + $registry.favoritesEntries.Count | Should -Be 1 + } + } + AfterEach { Remove-Module PowerShellRun -Force } diff --git a/tests/Public/Add-PSRunFunction.Tests.ps1 b/tests/Public/Add-PSRunFunction.Tests.ps1 index 7ed9ecb..3816c52 100644 --- a/tests/Public/Add-PSRunFunction.Tests.ps1 +++ b/tests/Public/Add-PSRunFunction.Tests.ps1 @@ -40,6 +40,17 @@ $function:Test = $null } + It 'should accept a pipeline input' { + Enable-PSRunEntry -Category Function + function global:Test {} + 'Test' | Add-PSRunFunction + InModuleScope 'PowerShellRun' { + $registry = $script:globalStore.GetRegistry('FunctionRegistry') + $registry.entries.Count | Should -Be 1 + } + $function:Test = $null + } + AfterEach { Remove-Module PowerShellRun -Force } diff --git a/tests/Public/Add-PSRunScriptBlock.Tests.ps1 b/tests/Public/Add-PSRunScriptBlock.Tests.ps1 index eeb9a46..581bcc1 100644 --- a/tests/Public/Add-PSRunScriptBlock.Tests.ps1 +++ b/tests/Public/Add-PSRunScriptBlock.Tests.ps1 @@ -29,6 +29,15 @@ } } + It 'should accept a pipeline input' { + Enable-PSRunEntry -Category Script + { 'hello' } | Add-PSRunScriptBlock -Name 'Custom Name' + InModuleScope 'PowerShellRun' { + $registry = $script:globalStore.GetRegistry('ScriptRegistry') + $registry.entries.Count | Should -Be 1 + } + } + AfterEach { Remove-Module PowerShellRun -Force } diff --git a/tests/Public/Add-PSRunScriptFile.Tests.ps1 b/tests/Public/Add-PSRunScriptFile.Tests.ps1 index 7fbd35f..7023d18 100644 --- a/tests/Public/Add-PSRunScriptFile.Tests.ps1 +++ b/tests/Public/Add-PSRunScriptFile.Tests.ps1 @@ -29,6 +29,15 @@ } } + It 'should accept a pipeline input' { + Enable-PSRunEntry -Category Script + 'D:/test.ps1' | Add-PSRunScriptFile + InModuleScope 'PowerShellRun' { + $registry = $script:globalStore.GetRegistry('ScriptRegistry') + $registry.entries.Count | Should -Be 1 + } + } + AfterEach { Remove-Module PowerShellRun -Force } From a03e237f0110715b225acd5de85e8089f04c97ea Mon Sep 17 00:00:00 2001 From: mdgrs <81177095+mdgrs-mei@users.noreply.github.com> Date: Sun, 11 Jan 2026 15:31:52 +0900 Subject: [PATCH 4/4] Add ValueFromPipelineByPropertyName to Invoke-PSRun and Invoke-PSRunPrompt --- module/PowerShellRun/Public/Invoke-PSRun.ps1 | 59 ++++++++++--------- .../Public/Invoke-PSRunPrompt.ps1 | 8 ++- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/module/PowerShellRun/Public/Invoke-PSRun.ps1 b/module/PowerShellRun/Public/Invoke-PSRun.ps1 index 4adaaf1..5b94b68 100644 --- a/module/PowerShellRun/Public/Invoke-PSRun.ps1 +++ b/module/PowerShellRun/Public/Invoke-PSRun.ps1 @@ -20,44 +20,47 @@ Invoke-PSRun function Invoke-PSRun { [CmdletBinding()] param ( + [Parameter(ValueFromPipelineByPropertyName = $true)] [String]$InitialQuery ) - $script:globalStore.UpdateEntries() - if ($script:globalStore.entries.Count -eq 0) { - Write-Error -Message 'There is no entry.' -Category InvalidOperation - return - } + process { + $script:globalStore.UpdateEntries() + if ($script:globalStore.entries.Count -eq 0) { + Write-Error -Message 'There is no entry.' -Category InvalidOperation + return + } - if ($InitialQuery) { - $prevContext = [PowerShellRun.SelectorContext]::new() - $prevContext.Query = $InitialQuery - } else { - $prevContext = $null - } + if ($InitialQuery) { + $prevContext = [PowerShellRun.SelectorContext]::new() + $prevContext.Query = $InitialQuery + } else { + $prevContext = $null + } - while ($true) { - $mode = [PowerShellRun.SelectorMode]::SingleSelection - $result = [PowerShellRun.Selector]::Open($script:globalStore.entries, $mode, $script:globalStore.psRunSelectorOption, $prevContext) - $prevContext = $result.Context + while ($true) { + $mode = [PowerShellRun.SelectorMode]::SingleSelection + $result = [PowerShellRun.Selector]::Open($script:globalStore.entries, $mode, $script:globalStore.psRunSelectorOption, $prevContext) + $prevContext = $result.Context - if ($result.FocusedEntry) { - $callback = $result.FocusedEntry.UserData.ScriptBlock - $argumentList = @{ - Result = $result - ArgumentList = $result.FocusedEntry.UserData.ArgumentList + if ($result.FocusedEntry) { + $callback = $result.FocusedEntry.UserData.ScriptBlock + $argumentList = @{ + Result = $result + ArgumentList = $result.FocusedEntry.UserData.ArgumentList + } + & $callback $argumentList + + if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::QuitWithBackspaceOnEmptyQuery) { + continue + } } - & $callback $argumentList - if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::QuitWithBackspaceOnEmptyQuery) { + if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::Restart) { + $prevContext = $null continue } + break } - - if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::Restart) { - $prevContext = $null - continue - } - break } } diff --git a/module/PowerShellRun/Public/Invoke-PSRunPrompt.ps1 b/module/PowerShellRun/Public/Invoke-PSRunPrompt.ps1 index 0452c77..210556a 100644 --- a/module/PowerShellRun/Public/Invoke-PSRunPrompt.ps1 +++ b/module/PowerShellRun/Public/Invoke-PSRunPrompt.ps1 @@ -31,11 +31,15 @@ function Invoke-PSRunPrompt { [CmdletBinding()] [OutputType([PowerShellRun.PromptResult])] param ( + [Parameter(ValueFromPipelineByPropertyName = $true)] [PowerShellRun.SelectorOption]$Option = $script:globalStore.defaultSelectorOption, + [Parameter(ValueFromPipelineByPropertyName = $true)] [PowerShellRun.PromptContext]$Context ) - $result = [PowerShellRun.Prompt]::Open($Option, $Context) - $result + process { + $result = [PowerShellRun.Prompt]::Open($Option, $Context) + $result + } }