Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AsNewFile switch to Out-CurrentFile #869

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added AsNewFile switch, plus, if a file is not open, it creates a n…
…ew one
  • Loading branch information
dfinke committed Feb 17, 2019
commit 70c0a95250d427ae902a2e95e7b4b18599e15f0e
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,31 @@ function Out-CurrentFile {
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline, Mandatory=$true)]
[Switch]$AsNewFile,
dfinke marked this conversation as resolved.
Show resolved Hide resolved
[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)
}
}