Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of integrating help #94

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ function InDisabledRepository {
return $false
}

<#
.SYNOPSIS
Enables Git colors.
#>
function Enable-GitColors {
$env:TERM = 'cygwin'
}
Expand Down Expand Up @@ -266,18 +270,39 @@ function Get-SshPath($File = 'id_rsa')
Resolve-Path (Join-Path $home ".ssh\$File") -ErrorAction SilentlyContinue 2> $null
}

# Add a key to the SSH agent
function Add-SshKey() {
<#
.SYNOPSIS
Add a key to the SSH agent
.DESCRIPTION
Adds one or more SSH keys to the SSH agent.
.EXAMPLE
Add-SshKey

Description
-----------
Adds ~\.ssh\id_rsa to the SSH agent.
.EXAMPLE
Add-SshKey ~\.ssh\mykey, ~\.ssh\myotherkey

Description
-----------
Adds ~\.ssh\mykey and ~\.ssh\myotherkey to the SSH agent.
#>
function Add-SshKey {
[CmdletBinding()]
[OutputType([void])]
Param
(
)
$sshAdd = Get-Command ssh-add -TotalCount 1 -ErrorAction SilentlyContinue
if (!$sshAdd) { Write-Warning 'Could not find ssh-add'; return }

if ($args.Count -eq 0) {
$sshPath = Get-SshPath
if ($sshPath) { & $sshAdd $sshPath }
} else {
foreach ($value in $args) {
& $sshAdd $value
}
if (-not $args) {
$args = Get-SshPath
}
foreach ($value in $args) {
Write-Verbose "Adding key '$value'"
& $sshAdd $value
}
}

Expand Down
79 changes: 79 additions & 0 deletions about_posh-git.help.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
posh-git is a PowerShell module which provides 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.
E.g. git ch<tab> -> git checkout

Other goodies
-------------

>> ssh-agent wrappers: Get-SshAgent, Start-SshAgent, Stop-ShhAgent, Add-SshKey
>> Update-AllBranches

Usage
-----

See profile.example.ps1 as to how you can integrate the tab completion and/or git prompt into your own profile. Prompt formatting, among other things, can be customized using $GitPromptSettings, $GitTabSettings and $TortoiseGitSettings.

Note on performance: displaying file status in the git prompt for a very large repo can be prohibitively slow. Rather than turn off file status entirely, you can disable it on a repo-by-repo basis by adding individual repository paths to $GitPromptSettings.RepositoriesInWhichToDisableFileStatus.

The Prompt
----------

PowerShell generates its prompt by executing a 'prompt' function, if one exists. posh-git defines such a function in profile.example.ps1 that outputs the current working directory followed by an abbreviated 'git status':

C:\Users\Keith [master]>

By default, the status summary has the following format:

[{HEAD-name} +A ~B -C !D | +E ~F -G !H]

>> {HEAD-name} is the current branch, or the SHA of a detached HEAD
>> Cyan means the branch matches its remote
>> Green means the branch is ahead of its remote (green light to push)
>> Red means the branch is behind its remote
>> Yellow means the branch is both ahead of and behind its remote

>> ABCD represent the index; EFGH represent the working directory
>> + = Added files
>> ~ = Modified files
>> - = Removed files
>> ! = Conflicted files
>> As in 'git status', index status is dark green and working directory status is dark red

For example, a status of [master +0 ~2 -1 | +1 ~1 -0] corresponds to the following 'git status':

# On branch master
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: this-changed.txt
# modified: this-too.txt
# deleted: gone.ps1
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: not-staged.ps1
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# new.file

Based on work by
----------------

>> Keight Dahlby, http://solutionizing.net/
>> Mark Embling, http://www.markembling.info/
>> Jeremy Skinner, http://www.jeremyskinner.co.uk/
>> Many other contributors - thank you, thank you, thank you!