Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/DiffGist.psm1 b/DiffGist.psm1
- index 89004da..a57686d 100644
- --- a/DiffGist.psm1
- +++ b/DiffGist.psm1
- @@ -1,11 +1,9 @@
- . (join-path $PSScriptRoot "/json 1.7.ps1")
- -
- function Get-Github-Credential($username) {
- $host.ui.PromptForCredential("Github Credential", "Please enter your Github user name and password.", $username, "")
- }
- -
- -function New-Gist {
- +function New-DiffGist {
- <#
- .Synopsis
- Publishes Github Gists of current git diff.
- @@ -23,34 +21,31 @@ function New-Gist {
- The Github username which will own this Gist.
- .Parameter Private
- - When specified, the Gist will be made private. Default is public.
- + When specified, the Gist will be made private. Default is private.
- .Example
- diffgist -Description "Hello.js greets all visitors"
- - Publishing a public Gist
- + Publishing a private Gist
- .Example
- - gist -File "Hello.js" -Description "Hello.js greets all visitors" -Private
- - Publishing a private Gist
- + diffgist -Name "Hello" -Description "Hello.js greets all visitors" -Public
- + Publishing a public Gist
- #>
- Param(
- [Parameter(Position=0, ValueFromPipeline=$true)]
- - [string]$Name = $null,
- + [string]$Name = "current.diff",
- [string]$Description = "",
- [string]$Username = $null,
- - [switch]$Private = $false
- + [switch]$Public = $false
- )
- BEGIN {
- $files = @{}
- }
- PROCESS {
- - if ($Name -eq $null) {
- - write-host "You need to specify -Name parameter."
- - return
- - }
- -
- - $content = git diff
- + $difffile = git diff | Out-File "_current.diff"
- + $content = [IO.File]::ReadAllText("_current.diff")
- + [IO.File]::Delete("_current.diff")
- $content = $content -replace "\\\\", "\\\\\\\\"
- $content = $content -replace "`t", "\\t"
- @@ -59,7 +54,7 @@ function New-Gist {
- $content = $content -replace """", "\\"""
- $content = $content -replace "/", "\\/"
- - $files.Add($filename, $content)
- + $files.Add($Name, $content)
- }
- END {
- @@ -67,14 +62,14 @@ function New-Gist {
- $request = [Net.WebRequest]::Create($apiurl)
- - $credential = $(Get-Github-Credential $Username)
- + $credential = $(Get-Github-Credential $Username)
- if($credential -eq $null) {
- write-host "Github credentials are required."
- return
- }
- - $username = $credential.Username.Substring(1)
- + $username = $credential.Username
- $password = $credential.Password
- $bstrpassword= [Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)
- @@ -96,7 +91,7 @@ function New-Gist {
- $filesjson = $filesjson.TrimEnd(',')
- - $isprivate = $Private.ToString().ToLower()
- + $ispublic = $Public.ToString().ToLower()
- $body = "{
- ""description"": """ + $Description + """,
- @@ -104,8 +99,6 @@ function New-Gist {
- ""files"": {" + $filesjson + "}
- }"
- - write-host $body
- -
- $bytes = [text.encoding]::Default.getbytes($body)
- $request.ContentLength = $bytes.Length
- @@ -137,9 +130,11 @@ function New-Gist {
- $url = $result.html_url
- write-output $url
- +
- + start $url
- }
- }
- -new-alias diffgist Diff-Gist
- +new-alias diffgist New-DiffGist
- -export-modulemember -alias * -function Diff-Gist
- +export-modulemember -alias * -function New-DiffGist
- diff --git a/build.ps1 b/build.ps1
- index 81affd0..bc9e5e3 100644
- --- a/build.ps1
- +++ b/build.ps1
- @@ -1,2 +1,2 @@
- New-ModuleManifest -Path PsGist.psd1 -Author "Ryan Cromwell" -CompanyName "EchelonTouch" -ModuleToProcess .\\PsGist.psm1 -Description "PsGist publishes Github Gists" -Copyright ""
- -
- +New-ModuleManifest -Path DiffGist.psd1 -Author "Tim Heuer" -CompanyName "Tim Heuer" -ModuleToProcess .\\DiffGist.psm1 -Description "DiffGist publishes Github Gists based on current git diff" -Copyright ""
- \\ No newline at end of file
Add Comment
Please, Sign In to add comment