@ Paul-
Mój profil PowerShell dla Git jest opartym na scenariuszu I znaleźć tutaj:
http://techblogging.wordpress.com/2008/10/12/displaying-git-branch-on-your-powershell-prompt/
Mam zmodyfikowanej go trochę, aby wyświetlić ścieżkę i trochę formatowania. Ustawia również ścieżkę do mojej lokalizacji odbiornika Git, ponieważ używam PortableGit.
# General variables
$pathToPortableGit = "D:\shared_tools\tools\PortableGit"
$scripts = "D:\shared_tools\scripts"
# Add Git executables to the mix.
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";" + (Join-Path $pathToPortableGit "\bin") + ";" + $scripts, "Process")
# Setup Home so that Git doesn't freak out.
[System.Environment]::SetEnvironmentVariable("HOME", (Join-Path $Env:HomeDrive $Env:HomePath), "Process")
$Global:CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$UserType = "User"
$CurrentUser.Groups | foreach {
if ($_.value -eq "S-1-5-32-544") {
$UserType = "Admin" }
}
function prompt {
# Fun stuff if using the standard PowerShell prompt; not useful for Console2.
# This, and the variables above, could be commented out.
if($UserType -eq "Admin") {
$host.UI.RawUI.WindowTitle = "" + $(get-location) + " : Admin"
$host.UI.RawUI.ForegroundColor = "white"
}
else {
$host.ui.rawui.WindowTitle = $(get-location)
}
Write-Host("")
$status_string = ""
$symbolicref = git symbolic-ref HEAD
if($symbolicref -ne $NULL) {
$status_string += "GIT [" + $symbolicref.substring($symbolicref.LastIndexOf("/") +1) + "] "
$differences = (git diff-index --name-status HEAD)
$git_update_count = [regex]::matches($differences, "M`t").count
$git_create_count = [regex]::matches($differences, "A`t").count
$git_delete_count = [regex]::matches($differences, "D`t").count
$status_string += "c:" + $git_create_count + " u:" + $git_update_count + " d:" + $git_delete_count + " | "
}
else {
$status_string = "PS "
}
if ($status_string.StartsWith("GIT")) {
Write-Host ($status_string + $(get-location) + ">") -nonewline -foregroundcolor yellow
}
else {
Write-Host ($status_string + $(get-location) + ">") -nonewline -foregroundcolor green
}
return " "
}
Jak dotąd, to pracował bardzo dobrze. Podczas repozytorium szczęśliwie wygląda tak:
GIT [master] c: 0 u: 1 d: 0 | J: \ Projects \ forks \ fluent-nhibernate>
* UWAGA: Zaktualizowane z sugestiami Jakuba Narębskiego.
- Usunięto wywołania statusu gałęzi/git.
- Rozwiązano problem polegający na tym, że "git config --global" - nie powiodło się, ponieważ $ HOME nie został ustawiony.
- Rozwiązano problem polegający na tym, że po przejściu do katalogu, który nie ma katalogu .git, formatowanie powróciłoby do znaku PS.
Jak włączyć ten moduł podczas uruchamiania? Wygląda na to, że Powerhell zapomina o tym module za każdym razem, gdy otwieram nowe wystąpienie. – Mihir
@Mihir musisz utworzyć profil, spójrz na odpowiedzi https://stackoverflow.com/questions/24914589/how-to-create-permanent-powershell-aliases# –
@NicolaPeluchetti Dzięki! Poszedłem za https://www.howtogeek.com/50236/customizing-your-powershell-profile/ i właśnie dodałem 'Import-Module posh-git' w moim profilu PowerShell. Pracował jak urok! – Mihir