From 7aba0e03229b438502f7ada976115b60c2dc5751 Mon Sep 17 00:00:00 2001 From: mdgrs <81177095+mdgrs-mei@users.noreply.github.com> Date: Mon, 12 Jan 2026 14:06:21 +0900 Subject: [PATCH 1/4] Fix argument passing to ScriptBlock and ScriptFile when argument is null --- module/PowerShellRun/Private/ScriptRegistry.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/module/PowerShellRun/Private/ScriptRegistry.ps1 b/module/PowerShellRun/Private/ScriptRegistry.ps1 index 76b0147..5e26068 100644 --- a/module/PowerShellRun/Private/ScriptRegistry.ps1 +++ b/module/PowerShellRun/Private/ScriptRegistry.ps1 @@ -37,7 +37,11 @@ class ScriptRegistry : EntryRegistry { $scriptBlock, $argumentList = $args[0].ArgumentList if ($result.KeyCombination -eq $script:globalStore.firstActionKey) { - & $scriptBlock @argumentList + if ($null -eq $argumentList) { + & $scriptBlock + } else { + & $scriptBlock @argumentList + } } elseif ($result.KeyCombination -eq $script:globalStore.secondActionKey) { $scriptBlock.ToString() } elseif ($result.KeyCombination -eq $script:globalStore.thirdActionKey) { @@ -63,7 +67,11 @@ class ScriptRegistry : EntryRegistry { $filePath, $argumentList = $args[0].ArgumentList if ($result.KeyCombination -eq $script:globalStore.firstActionKey) { - & $filePath @argumentList + if ($null -eq $argumentList) { + & $filePath + } else { + & $filePath @argumentList + } } elseif ($result.KeyCombination -eq $script:globalStore.secondActionKey) { & $script:globalStore.defaultEditorScript $filePath } elseif ($result.KeyCombination -eq $script:globalStore.thirdActionKey) { From 9ed46850be8c78a23a832e16c49acd3eaa20c6dc Mon Sep 17 00:00:00 2001 From: mdgrs <81177095+mdgrs-mei@users.noreply.github.com> Date: Mon, 12 Jan 2026 14:27:16 +0900 Subject: [PATCH 2/4] Add ArgumentList to Add-PSRunFunction --- .../PowerShellRun/Private/FunctionRegistry.ps1 | 18 +++++++++++------- .../PowerShellRun/Public/Add-PSRunFunction.ps1 | 8 +++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/module/PowerShellRun/Private/FunctionRegistry.ps1 b/module/PowerShellRun/Private/FunctionRegistry.ps1 index 64d71d2..6dd3135 100644 --- a/module/PowerShellRun/Private/FunctionRegistry.ps1 +++ b/module/PowerShellRun/Private/FunctionRegistry.ps1 @@ -31,10 +31,14 @@ class FunctionRegistry : EntryRegistry { $this.callback = { $result = $args[0].Result - $functionName = $args[0].ArgumentList + $functionName, $argumentList = $args[0].ArgumentList if ($result.KeyCombination -eq $script:globalStore.firstActionKey) { - & $functionName + if ($null -eq $argumentList) { + & $functionName + } else { + & $functionName @argumentList + } } elseif ($result.KeyCombination -eq $script:globalStore.secondActionKey) { $function = Get-Command $functionName $function.Definition @@ -87,7 +91,7 @@ class FunctionRegistry : EntryRegistry { if ($functionAtStart -eq $function.ScriptBlock) { continue } - $entry = $this.CreateFunctionEntry($function) + $entry = $this.CreateFunctionEntry($function, $null) $this.entries.Add($entry) $this.isEntryUpdated = $true } @@ -95,7 +99,7 @@ class FunctionRegistry : EntryRegistry { $this.functionsAtRegisterStart = $null } - [void] AddFunction($functionName, $icon, $name, $description, $preview, [EntryGroup]$entryGroup) { + [void] AddFunction($functionName, $argumentList, $icon, $name, $description, $preview, [EntryGroup]$entryGroup) { if (-not $this.isEnabled) { Write-Warning -Message '"Function" category is disabled.' return @@ -107,7 +111,7 @@ class FunctionRegistry : EntryRegistry { return } - $entry = $this.CreateFunctionEntry($function) + $entry = $this.CreateFunctionEntry($function, $argumentList) if ($icon) { $entry.Icon = $icon } if ($name) { $entry.Name = $name } if ($description) { $entry.Description = $description } @@ -121,7 +125,7 @@ class FunctionRegistry : EntryRegistry { } } - [PowerShellRun.SelectorEntry] CreateFunctionEntry($function) { + [PowerShellRun.SelectorEntry] CreateFunctionEntry($function, $argumentList) { $help = Get-Help $function.Name $customAttributes = $this.GetFunctionCustomAttributes($help) @@ -142,7 +146,7 @@ class FunctionRegistry : EntryRegistry { $entry.UserData = @{ ScriptBlock = $this.callback - ArgumentList = $function.Name + ArgumentList = $function.Name, $argumentList } return $entry } diff --git a/module/PowerShellRun/Public/Add-PSRunFunction.ps1 b/module/PowerShellRun/Public/Add-PSRunFunction.ps1 index cd2e9ed..ff5fd9e 100644 --- a/module/PowerShellRun/Public/Add-PSRunFunction.ps1 +++ b/module/PowerShellRun/Public/Add-PSRunFunction.ps1 @@ -9,6 +9,9 @@ The function must be global and defined before calling this function. .PARAMETER FunctionName The function name you would like to add as an entry. +.PARAMETER ArgumentList +The arguments that are passed to the function. + .PARAMETER Icon The icon string. @@ -44,6 +47,9 @@ function Add-PSRunFunction { [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [String]$FunctionName, + [Parameter(ValueFromPipelineByPropertyName = $true)] + [Object[]]$ArgumentList, + [Parameter(ValueFromPipelineByPropertyName = $true)] [String]$Icon, @@ -62,6 +68,6 @@ function Add-PSRunFunction { process { $registry = $script:globalStore.GetRegistry('FunctionRegistry') - $registry.AddFunction($FunctionName, $Icon, $Name, $Description, $Preview, $EntryGroup) + $registry.AddFunction($FunctionName, $ArgumentList, $Icon, $Name, $Description, $Preview, $EntryGroup) } } From 52b2c7aeb7979cb4329bea42f8c60f2cd58cdae9 Mon Sep 17 00:00:00 2001 From: mdgrs <81177095+mdgrs-mei@users.noreply.github.com> Date: Mon, 12 Jan 2026 20:15:52 +0900 Subject: [PATCH 3/4] Show default parameters for Invoke with arguments action --- module/PowerShellRun/Private/GlobalStore.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/module/PowerShellRun/Private/GlobalStore.ps1 b/module/PowerShellRun/Private/GlobalStore.ps1 index 630a1f5..f12c947 100644 --- a/module/PowerShellRun/Private/GlobalStore.ps1 +++ b/module/PowerShellRun/Private/GlobalStore.ps1 @@ -335,6 +335,16 @@ class GlobalStore { return @{} } + $initialPromptContexts = @() + for ($i = 0; $i -lt $astParameters.Count; ++$i) { + $astParameter = $astParameters[$i] + $promptContext = [PowerShellRun.PromptContext]::new() + if ($astParameter.DefaultValue.Value -is [String]) { + $promptContext.Input = $astParameter.DefaultValue.Value + } + $initialPromptContexts += $promptContext + } + $option = $this.GetPSRunSelectorOption() $option.QuitWithBackspaceOnEmptyQuery = $true @@ -344,6 +354,9 @@ class GlobalStore { $parameterName = $astParameters[$i].Name.VariablePath.UserPath.Replace('$', '') $option.Prompt = $parameterName $promptContext = $promptContexts[$parameterName] + if ($null -eq $promptContext) { + $promptContext = $initialPromptContexts[$i] + } $promptResult = Invoke-PSRunPrompt -Option $option -Context $promptContext if ([PowerShellRun.ExitStatus]::Type -eq [PowerShellRun.ExitType]::QuitWithBackspaceOnEmptyQuery) { From 9878bc974e93d0f0bd81384f6617b45534ad5dc6 Mon Sep 17 00:00:00 2001 From: mdgrs <81177095+mdgrs-mei@users.noreply.github.com> Date: Mon, 12 Jan 2026 20:42:53 +0900 Subject: [PATCH 4/4] Show ArgumentList as default if it exists --- module/PowerShellRun/Private/FunctionRegistry.ps1 | 2 +- module/PowerShellRun/Private/GlobalStore.ps1 | 8 +++++--- module/PowerShellRun/Private/ScriptRegistry.ps1 | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/module/PowerShellRun/Private/FunctionRegistry.ps1 b/module/PowerShellRun/Private/FunctionRegistry.ps1 index 6dd3135..c7d255a 100644 --- a/module/PowerShellRun/Private/FunctionRegistry.ps1 +++ b/module/PowerShellRun/Private/FunctionRegistry.ps1 @@ -50,7 +50,7 @@ class FunctionRegistry : EntryRegistry { $function.ScriptBlock.Ast.Body.ParamBlock.Parameters } - $parameters = $script:globalStore.GetParameterList($astParameters) + $parameters = $script:globalStore.GetParameterList($astParameters, $argumentList) if ($null -ne $parameters) { & $functionName @parameters } diff --git a/module/PowerShellRun/Private/GlobalStore.ps1 b/module/PowerShellRun/Private/GlobalStore.ps1 index f12c947..19bf95a 100644 --- a/module/PowerShellRun/Private/GlobalStore.ps1 +++ b/module/PowerShellRun/Private/GlobalStore.ps1 @@ -330,7 +330,7 @@ class GlobalStore { } } - [Object] GetParameterList($astParameters) { + [Object] GetParameterList($astParameters, $argumentList) { if (-not $astParameters) { return @{} } @@ -339,8 +339,10 @@ class GlobalStore { for ($i = 0; $i -lt $astParameters.Count; ++$i) { $astParameter = $astParameters[$i] $promptContext = [PowerShellRun.PromptContext]::new() - if ($astParameter.DefaultValue.Value -is [String]) { - $promptContext.Input = $astParameter.DefaultValue.Value + if (($null -ne $argumentList) -and ($null -ne $argumentList[$i].ToString)) { + $promptContext.Input = $argumentList[$i].ToString() + } elseif ($null -ne $astParameter.DefaultValue.Value.ToString) { + $promptContext.Input = $astParameter.DefaultValue.Value.ToString() } $initialPromptContexts += $promptContext } diff --git a/module/PowerShellRun/Private/ScriptRegistry.ps1 b/module/PowerShellRun/Private/ScriptRegistry.ps1 index 5e26068..5c130e2 100644 --- a/module/PowerShellRun/Private/ScriptRegistry.ps1 +++ b/module/PowerShellRun/Private/ScriptRegistry.ps1 @@ -46,7 +46,7 @@ class ScriptRegistry : EntryRegistry { $scriptBlock.ToString() } elseif ($result.KeyCombination -eq $script:globalStore.thirdActionKey) { $astParameters = $scriptBlock.Ast.ParamBlock.Parameters - $parameters = $script:globalStore.GetParameterList($astParameters) + $parameters = $script:globalStore.GetParameterList($astParameters, $argumentList) if ($null -ne $parameters) { & $scriptBlock @parameters }