Instantly share code, notes, and snippets.

Embed
What would you like to do?
A PowerShell ISE script to send selected text as a Github gist. This requires my New-GitHubGist function.
#requires -version 4.0
#dot source the script with the New-GitHubGist function
. C:\scripts\New-GitHubGist.ps1
Function SendTo-Gist {
[cmdletbinding()]
Param(
[Parameter(Position = 0)]
[ValidateNotNullorEmpty()]
[string[]]$Text = $psise.CurrentFile.Editor.SelectedText,
[switch]$Private
)
#hashtable of parameters to splat to New-GitHubGist
$param = @{
name = (Read-Host "Enter a file name for your gist")
description = (Read-Host "Enter a description")
Content = $Text
}
if ($private) {
$param.Add("Private",$True)
}
New-GitHubGist @param
}
#add a menu shortcut
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.add("Send to Gist",{SendTo-Gist -text $psise.CurrentFile.Editor.SelectedText },$null) | out-null
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.add("Send to Private Gist",{SendTo-Gist -text $psise.CurrentFile.Editor.SelectedText -private},$null) | out-null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment