@@ -281,6 +281,7 @@ function Get-PathStringComparison {
281281function Get-PromptPath {
282282 $settings = $global :GitPromptSettings
283283 $abbrevHomeDir = $settings -and $settings.DefaultPromptAbbreviateHomeDirectory
284+ $abbrevGitDir = $settings -and $settings.DefaultPromptAbbreviateGitDirectory
284285
285286 # A UNC path has no drive so it's better to use the ProviderPath e.g. "\\server\share".
286287 # However for any path with a drive defined, it's better to use the Path property.
@@ -289,10 +290,22 @@ function Get-PromptPath {
289290 $pathInfo = $ExecutionContext.SessionState.Path.CurrentLocation
290291 $currentPath = if ($pathInfo.Drive ) { $pathInfo.Path } else { $pathInfo.ProviderPath }
291292
293+ # Look up the git root
294+ if ($abbrevGitDir ) {
295+ $gitPath = $ (Get-GitDirectory )
296+ if ($gitPath ) { $gitPath = $ (Split-Path $gitPath - Parent) }
297+ }
298+
292299 $stringComparison = Get-PathStringComparison
293300
301+ # Abbreviate path by replacing beginning of path with - *iff* the path is under a git repository
302+ if ($abbrevGitDir -and $currentPath -and $gitPath -and
303+ $currentPath.StartsWith ($gitPath , $stringComparison )) {
304+ $removePath = $ (Split-Path $gitPath - Parent)
305+ $currentPath = " -" + $currentPath.SubString ($removePath.Length )
306+ }
294307 # Abbreviate path by replacing beginning of path with ~ *iff* the path is under the user's home dir
295- if ($abbrevHomeDir -and $currentPath -and ! $currentPath.Equals ($Home , $stringComparison ) -and
308+ elseif ($abbrevHomeDir -and $currentPath -and ! $currentPath.Equals ($Home , $stringComparison ) -and
296309 $currentPath.StartsWith ($Home , $stringComparison )) {
297310
298311 $currentPath = " ~" + $currentPath.SubString ($Home.Length )
0 commit comments