From 70c0a95250d427ae902a2e95e7b4b18599e15f0e Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 17 Feb 2019 12:00:41 -0500 Subject: [PATCH 1/2] Added `AsNewFile` switch, plus, if a file is not open, it creates a new one --- .../Commands/Public/Out-CurrentFile.ps1 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 index 5d0b5cf5c..65638b661 100644 --- a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 @@ -9,14 +9,31 @@ 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) } } From 3c88f17b5d428d6c4e08c22a25a0534412cc996b Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Mon, 18 Feb 2019 14:12:24 -0500 Subject: [PATCH 2/2] Update module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 Co-Authored-By: dfinke --- .../PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 index 65638b661..75c4a192d 100644 --- a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 +++ b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 @@ -10,6 +10,7 @@ function Out-CurrentFile { [CmdletBinding()] param( [Switch]$AsNewFile, + [Parameter(ValueFromPipeline, Mandatory = $true)] $InputObject )