diff --git a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 index 5d0b5cf5c..75c4a192d 100644 --- a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 @@ -9,14 +9,32 @@ function Out-CurrentFile { #> [CmdletBinding()] param( - [Parameter(ValueFromPipeline, Mandatory=$true)] + [Switch]$AsNewFile, + + [Parameter(ValueFromPipeline, Mandatory = $true)] $InputObject ) Begin { $objectsToWrite = @() } Process { $objectsToWrite += $InputObject } End { + + # If requested, create a new file + if ($AsNewFile) { + $psEditor.Workspace.NewFile() + } + $outputString = "@`"`r`n{0}`r`n`"@" -f ($objectsToWrite|out-string).Trim() + + try { + # If there is no file open + $psEditor.GetEditorContext() + } + catch { + # create a new one + $psEditor.Workspace.NewFile() + } + $psEditor.GetEditorContext().CurrentFile.InsertText($outputString) } }