Navigation Menu

Skip to content

Commit

Permalink
Converted to be a PS module.
Browse files Browse the repository at this point in the history
As a module, the idea is that it should be more portable and...
well, modular. Also changed to use newly added Test-LocalOrParentPath
to find the .git directory instead of asking git. It performs faster,
at least on my machine.
  • Loading branch information
drmohundro committed Mar 31, 2010
1 parent 66572b9 commit 0dc174d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
6 changes: 1 addition & 5 deletions GitUtils.ps1
@@ -1,12 +1,8 @@
# Inspired by Mark Embling
# http://www.markembling.info/view/my-ideal-powershell-prompt-with-git-integration

. .\Utils.ps1

function Get-GitDirectory {
Coalesce-Args `
(Get-Item '.\.git' -Force 2>$null).FullName `
{ git rev-parse --git-dir 2>$null }
Test-LocalOrParentPath .git
}

function Get-GitBranch($gitDir = $(Get-GitDirectory)) {
Expand Down
14 changes: 13 additions & 1 deletion Utils.ps1
Expand Up @@ -12,4 +12,16 @@ function Coalesce-Args {
}
$result
}
Set-Alias ?? Coalesce-Args

Remove-Item alias:/`?`? -Force
Set-Alias ?? Coalesce-Args -Force

function Test-LocalOrParentPath($path) {
$done = $false
do {
if (Test-Path $path) { return $true }
if (Test-Path ..) { return $false }
$path = "..\$path"
} while (!$done)
return $false
}
13 changes: 13 additions & 0 deletions posh-git.psm1
@@ -0,0 +1,13 @@
Push-Location $psScriptRoot
. ./Utils.ps1
. ./GitUtils.ps1
. ./GitPrompt.ps1
. ./GitTabExpansion.ps1
Pop-Location

Export-ModuleMember -Function @(
'Write-GitStatus',
'Get-GitStatus',
'Enable-GitColors',
'Get-GitDirectory',
'GitTabExpansion')
13 changes: 1 addition & 12 deletions profile.example.ps1
@@ -1,13 +1,4 @@
Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

# Git utils
. ./GitUtils.ps1
. ./GitPrompt.ps1

# Use Git tab expansion
. ./GitTabExpansion.ps1

Pop-Location
Import-Module posh-git

# Set up a simple prompt, adding the git prompt parts inside git repos
function prompt {
Expand Down Expand Up @@ -37,5 +28,3 @@ function TabExpansion($line, $lastWord) {
}

Enable-GitColors

Pop-Location

0 comments on commit 0dc174d

Please sign in to comment.