Skip to content

Instantly share code, notes, and snippets.

@jdhitsolutions
Last active November 13, 2020 18:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdhitsolutions/345a6b8e4c47440df5fb1dbcb987cb3e to your computer and use it in GitHub Desktop.
Save jdhitsolutions/345a6b8e4c47440df5fb1dbcb987cb3e to your computer and use it in GitHub Desktop.
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