The Kickstarter is live! Let's take Chocolatey to the next level!

13,988

Downloads

1,042

Downloads of v 0.5.0.201401009

10/9/2014

Last update

posh-git

0.5.0.201401009

This package was approved by moderator mwrock on 10/26/2014.

posh-git - A set of PowerShell scripts which provide Git/PowerShell integration.

To install posh-git, run the following command from the command line or from PowerShell:

C:\> choco install poshgit

Files

  • tools\chocolateyInstall.ps1 Show
    function Insert-Script([ref]$originalScript, $script) {
        if(!($originalScript.Value -Contains $script)) { $originalScript.Value += $script }
    }
    
    try {
        $binRoot = join-path $env:systemdrive 'tools'
        $oldPromptOverride = "if(Test-Path Function:\Prompt) {Rename-Item Function:\Prompt PrePoshGitPrompt -Force}"
        $newPromptOverride = "function Prompt() {if(Test-Path Function:\PrePoshGitPrompt){++`$global:poshScope; New-Item function:\script:Write-host -value `"param([object] ```$object, ```$backgroundColor, ```$foregroundColor, [switch] ```$nonewline) `" -Force | Out-Null;`$private:p = PrePoshGitPrompt; if(--`$global:poshScope -eq 0) {Remove-Item function:\Write-Host -Force}}PoshGitPrompt}"
        ### Using an environment variable to to define the bin root until we implement YAML configuration ###
        if($env:chocolatey_bin_root -ne $null){$binRoot = join-path $env:systemdrive $env:chocolatey_bin_root}
        $poshgitPath = join-path $binRoot 'poshgit'
    
        try {
          if (test-path($poshgitPath)) {
            Write-Host "Attempting to remove existing `'$poshgitPath`' prior to install."
            remove-item $poshgitPath -recurse -force
          }
        } catch {
          Write-Host 'Could not remove poshgit folder'
        }
    
        $poshGitInstall = if($env:poshGit -ne $null){ $env:poshGit } else {'https://github.com/dahlbyk/posh-git/zipball/master'}
        #Install-ChocolateyZipPackage 'poshgit' 'https://github.com/dahlbyk/posh-git/zipball/v0.4' $poshgitPath
        Install-ChocolateyZipPackage 'poshgit' $poshGitInstall $poshgitPath
        $pgitDir = [Array](Dir "$poshgitPath\*posh-git*\" | Sort-Object -Property LastWriteTime)[-1]
    
        if(Test-Path $PROFILE) {
            $oldProfile = [string[]](Get-Content $PROFILE)
            $newProfile = @()
            #If old profile exists replace with new one and make sure prompt preservation function is on top
            $pgitExample = "$pgitDir\profile.example.ps1"
            foreach($line in $oldProfile) {
                if($line.ToLower().Contains("$poshgitPath".ToLower())) {
                    Insert-Script ([REF]$newProfile) $oldPromptOverride
                    $line = ". '$pgitExample'"
                }
                if($line.Trim().Length -gt 0) {  $newProfile += $line }
            }
            #Save any previous Prompt logic
            Insert-Script ([REF]$newProfile) $oldPromptOverride
            Set-Content -path $profile -value $newProfile -Force
        }
    
    
        #------- ADDITIONAL SETUP -------#
        $subfolder = get-childitem $poshgitPath -recurse -include 'dahlbyk-posh-git-*' | select -First 1
        write-debug "Found and using folder `'$subfolder`'"
        #$installer = Join-Path $poshgitPath $subfolder #'dahlbyk-posh-git-60be436'
        $installer = Join-Path $subfolder 'install.ps1'
        & $installer
    
        $newProfile = [string[]](Get-Content $PROFILE)
        Insert-Script ([REF]$newProfile) "Rename-Item Function:\Prompt PoshGitPrompt -Force"
    
        #function that will run previous prompt logic and then the poshgit logic
        #all output from previous prompts will be swallowed
        Insert-Script ([REF]$newProfile) $newPromptOverride
        Set-Content -path $profile  -value $newProfile -Force
    
        Write-ChocolateySuccess 'poshgit'
    } catch {
      try {
        if($oldProfile){ Set-Content -path $PROFILE -value $oldProfile -Force }
      }
      catch{}
      Write-ChocolateyFailure 'poshgit' $($_.Exception.Message)
      throw
    }
    
    

Dependencies

Maintainers

Authors

Tags

Version History

Version Downloads Last updated
posh-git 0.4.0.20120717 11854 Tuesday, July 17, 2012
posh-git 0.4.0 308 Monday, May 14, 2012
posh-git 0.3.0.2 338 Friday, February 3, 2012
posh-git 0.3.0.1 321 Tuesday, August 23, 2011
posh-git 0.3 125 Tuesday, August 23, 2011

Discussion for the posh-git Package

Ground rules:

  • This discussion is only about posh-git and the posh-git package. If you have feedback for chocolatey, please contact the google group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • This is not a substitute for contacting package maintainers. Please use the link on the left side of this page or follow this link to contact maintainers.
  • Tell us what you love about the package or posh-git, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or got yas that you've found.

comments powered by Disqus