PoshCode Archive  Artifact [0cbbec4150]

Artifact 0cbbec4150d986e09c810c979d3bd408ead891d16a99d5256ac71c4b7f433785:

  • File Get-GitInfoForDirectory.ps1 — part of check-in [560d212c57] at 2018-06-10 14:11:08 on branch trunk — Get-GitInfoForDirectory Function – Git repo folder info gather function to Display Git Repo Status and Branch in the PowerShell Prompt. – Add Function to your Profile Script, and call from within the Prompt Function – Must have Git For Windows installed and its install directory added to the PATH (user: JayDeuce size: 1686)

# encoding: ascii
# api: powershell
# title: Get-GitInfoForDirectory
# description: Get-GitInfoForDirectory Function – Git repo folder info gather function to Display Git Repo Status and Branch in the PowerShell Prompt. – Add Function to your Profile Script, and call from within the Prompt Function – Must have Git For Windows installed and its install directory added to the PATH
# version: 0.1
# type: function
# author: JayDeuce
# license: CC0
# function: Get-GitInfoForDirectory
# x-poshcode-id: 6235
# x-archived: 2016-03-26T12:17:01
# x-published: 2016-02-25T05:16:00
#
#
function Get-GitInfoForDirectory {

    param (
    )

    begin {
        $gitBranch = (git branch)
        $gitStatus = (git status)
        $gitTextLine = ""
    }

    process {
        try {
            foreach ($branch in $gitBranch) {
                if ($branch -match '^\* (.*)') {
                    $gitBranchName = 'Git Repo - Branch: ' + $matches[1].ToUpper()
    	        }
            }
    
            if (!($gitStatus -like '*working directory clean*')) {
                $gitStatusMark = ' ' + '/' + ' Status: ' + 'NEEDS UPDATING'
            }
            elseif ($gitStatus -like '*Your branch is ahead*') {
                $gitStatusMark = ' ' + '/' + ' Status: ' + 'PUBLISH COMMITS'
            }
            else {
                $gitStatusMark = ' ' + '/' + ' Status: ' + 'UP TO DATE'
            }
        }
        catch {
        }
    }

    end {
        if ($gitBranch) { 
            $gitTextLine = ' {' + $gitBranchName + $gitStatusMark + '}'            
        }
        return $gitTextLine       
    }    
}