Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Limit path length in prompt (40 by default)

  • Loading branch information...
commit 5bee7b357f87fffc7117545e2d27f0a1b5e869f9 1 parent 3a11cdf
@dahlbyk authored
View
2  GitPrompt.ps1
@@ -46,6 +46,8 @@ $global:GitPromptSettings = New-Object PSObject -Property @{
EnableFileStatus = $true
RepositoriesInWhichToDisableFileStatus = @( ) # Array of repository paths
+ MaxPromptPathLength = 40
+
Debug = $false
}
View
10 Utils.ps1
@@ -28,6 +28,16 @@ function Get-LocalOrParentPath($path) {
return $null
}
+function Limit-Path ($path, $limit) {
+ if (!$path -or $path.Length -le $limit) { return $path }
+
+ $takeBefore = 1 + $path.IndexOf('\')
+ $between = '...'
+ $takeAfter = $path.IndexOf('\', $path.Length - ($limit - $between.Length - $takeBefore))
+ if ($takeAfter -lt 0) { $takeAfter = $path.LastIndexOf('\') }
+ $path.Substring(0, $takeBefore) + $between + $path.Substring($takeAfter, $path.Length - $takeAfter)
+}
+
function dbg ($Message, [Diagnostics.Stopwatch]$Stopwatch) {
if($Stopwatch) {
Write-Verbose ('{0:00000}:{1}' -f $Stopwatch.ElapsedMilliseconds,$Message) -Verbose # -ForegroundColor Yellow
View
1  posh-git.psm1
@@ -14,6 +14,7 @@ if (!$Env:HOME) { $Env:HOME = "$Env:HOMEDRIVE$Env:HOMEPATH" }
if (!$Env:HOME) { $Env:HOME = "$Env:USERPROFILE" }
Export-ModuleMember -Function @(
+ 'Limit-Path',
'Write-GitStatus',
'Get-GitStatus',
'Enable-GitColors',
View
2  profile.example.ps1
@@ -15,7 +15,7 @@ function prompt {
# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
- Write-Host($pwd) -nonewline
+ Write-Host (Limit-Path $pwd.Path $Global:GitPromptSettings.MaxPromptPathLength) -NoNewline
Write-VcsStatus
Please sign in to comment.
Something went wrong with that request. Please try again.