Skip to content

Commit

Permalink
Merge pull request #3 from dahlbyk/master
Browse files Browse the repository at this point in the history
merging latest
  • Loading branch information
paulmarsy committed May 17, 2015
2 parents c298ac0 + f948f5a commit 66200ac
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
7 changes: 6 additions & 1 deletion GitPrompt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
Debug = $false
}

$currentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdminProcess = $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

$adminHeader = if ($isAdminProcess) { 'Administrator: ' } else { '' }

$WindowTitleSupported = $true
if (Get-Module NuGet) {
$WindowTitleSupported = $false
Expand Down Expand Up @@ -138,7 +143,7 @@ function Write-GitStatus($status) {
}
$repoName = Split-Path -Leaf (Split-Path $status.GitDir)
$prefix = if ($s.EnableWindowTitle -is [string]) { $s.EnableWindowTitle } else { '' }
$Host.UI.RawUI.WindowTitle = "$prefix$repoName [$($status.Branch)]"
$Host.UI.RawUI.WindowTitle = "$script:adminHeader$prefix$repoName [$($status.Branch)]"
}
} elseif ( $Global:PreviousWindowTitle ) {
$Host.UI.RawUI.WindowTitle = $Global:PreviousWindowTitle
Expand Down
6 changes: 6 additions & 0 deletions GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ function GitTabExpansion($lastBlock) {
return $tortoiseGitCommands | where { $_ -like "$($matches['cmd'])*" }
}

# Handles gitk
if($lastBlock -match "^$(Get-AliasPattern gitk).* (?<ref>\S*)$"){
return gitBranches $matches['ref'] $true
}

switch -regex ($lastBlock -replace "^$(Get-AliasPattern git) ","") {

# Handles git <cmd> <op>
Expand Down Expand Up @@ -305,6 +310,7 @@ function TabExpansion($line, $lastWord) {
# Execute git tab completion for all git-related commands
"^$(Get-AliasPattern git) (.*)" { GitTabExpansion $lastBlock }
"^$(Get-AliasPattern tgit) (.*)" { GitTabExpansion $lastBlock }
"^$(Get-AliasPattern gitk) (.*)" { GitTabExpansion $lastBlock }

# Fall back on existing tab expansion
default { if (Test-Path Function:\TabExpansionBackup) { TabExpansionBackup $line $lastWord } }
Expand Down
26 changes: 26 additions & 0 deletions GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,28 @@ function Get-SshAgent() {
return 0
}

# Attempt to guess Pageant's location
function Guess-Pageant() {
Write-Verbose "Pageant not in path. Trying to guess location."
$gitSsh = $env:GIT_SSH
if ($gitSsh -and (test-path $gitSsh)) {
$pageant = join-path (split-path $gitSsh) pageant
}
if (!(get-command $pageant -Erroraction SilentlyContinue)) { return } # Guessing failed.
else { return $pageant }
}

# Attempt to guess $program's location. For ssh-agent/ssh-add.
function Guess-Ssh($program = 'ssh-agent') {
Write-Verbose "$program not in path. Trying to guess location."
$gitItem = Get-Command git -Erroraction SilentlyContinue | Get-Item
if ($gitItem -eq $null) { Write-Warning 'git not in path'; return }
$sshLocation = join-path $gitItem.directory.parent.fullname bin
$sshLocation = join-path $sshLocation $program
if (!(get-command $sshLocation -Erroraction SilentlyContinue)) { return } # Guessing failed.
else { return $sshLocation }
}

# Loosely based on bash script from http://help.github.com/ssh-key-passphrases/
function Start-SshAgent([switch]$Quiet) {
[int]$agentPid = Get-SshAgent
Expand All @@ -277,10 +299,12 @@ function Start-SshAgent([switch]$Quiet) {
if ($env:GIT_SSH -imatch 'plink') {
Write-Host "GIT_SSH set to $($env:GIT_SSH), using Pageant as SSH agent."
$pageant = Get-Command pageant -TotalCount 1 -Erroraction SilentlyContinue
$pageant = if ($pageant) {$pageant} else {Guess-Pageant}
if (!$pageant) { Write-Warning "Could not find Pageant."; return }
& $pageant
} else {
$sshAgent = Get-Command ssh-agent -TotalCount 1 -ErrorAction SilentlyContinue
$sshAgent = if ($sshAgent) {$sshAgent} else {Guess-Ssh('ssh-agent')}
if (!$sshAgent) { Write-Warning 'Could not find ssh-agent'; return }

& $sshAgent | foreach {
Expand All @@ -302,6 +326,7 @@ function Get-SshPath($File = 'id_rsa')
function Add-SshKey() {
if ($env:GIT_SSH -imatch 'plink') {
$pageant = Get-Command pageant -Erroraction SilentlyContinue | Select -First 1 -ExpandProperty Name
$pageant = if ($pageant) {$pageant} else {Guess-Pageant}
if (!$pageant) { Write-Warning 'Could not find Pageant'; return }

if ($args.Count -eq 0) {
Expand All @@ -317,6 +342,7 @@ function Add-SshKey() {
}
} else {
$sshAdd = Get-Command ssh-add -TotalCount 1 -ErrorAction SilentlyContinue
$sshAdd = if ($sshAdd) {$sshAdd} else {Guess-Ssh('ssh-add')}
if (!$sshAdd) { Write-Warning 'Could not find ssh-add'; return }

if ($args.Count -eq 0) {
Expand Down
15 changes: 13 additions & 2 deletions posh-git.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
param([switch]$NoVersionWarn = $false)

if (Get-Module posh-git) { return }

$psv = $PSVersionTable.PSVersion

if ($psv.Major -lt 3 -and !$NoVersionWarn) {
Write-Warning ("posh-git support for PowerShell 2.0 is deprecated; you have version $($psv).`n" +
"To download version 3.0, please visit https://www.microsoft.com/en-us/download/details.aspx?id=34595`n" +
"For more information and to discuss this, please visit https://github.com/dahlbyk/posh-git/issues/163`n" +
"To suppress this warning, change your profile to include 'Import-Module posh-git -Args `$true'.")
}

Push-Location $psScriptRoot
.\CheckVersion.ps1 > $null

Expand All @@ -23,8 +34,8 @@ Export-ModuleMember `
'Invoke-NullCoalescing',
'Write-GitStatus',
'Write-Prompt',
'Get-GitStatus',
'Enable-GitColors',
'Get-GitStatus',
'Enable-GitColors',
'Get-GitDirectory',
'TabExpansion',
'Get-AliasPattern',
Expand Down
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ A set of PowerShell scripts which provide Git/PowerShell integration

### Prompt for Git repositories
The prompt within Git repositories can show the current branch and the state of files (additions, modifications, deletions) within.

### Tab completion
Provides tab completion for common commands when using git.
Provides tab completion for common commands when using git.
E.g. `git ch<tab>` --> `git checkout`

Usage
-----

Expand All @@ -30,13 +30,13 @@ Install-Module posh-git
Installing (manual)
-------------------

0. Verify you have PowerShell 2.0 or better with $PSVersionTable.PSVersion
0. Verify you have PowerShell 2.0 or better with `$PSVersionTable.PSVersion`. PowerShell 3.0 is preferred as 2.0 support is deprecated.

1. Verify execution of scripts is allowed with `Get-ExecutionPolicy` (should be `RemoteSigned` or `Unrestricted`). If scripts are not enabled, run PowerShell as Administrator and call `Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm`.

2. Verify that `git` can be run from PowerShell.
If the command is not found, you will need to add a git alias or add `%ProgramFiles(x86)%\Git\cmd`
(or `%ProgramFiles%\Git\cmd` if you're still on 32-bit) to your PATH environment variable.
(or `%ProgramFiles%\Git\cmd` if you're still on 32-bit) to your `PATH` environment variable.

3. Clone the posh-git repository to your local machine.

Expand Down

0 comments on commit 66200ac

Please sign in to comment.