Skip to content

Commit

Permalink
Shorten window title text
Browse files Browse the repository at this point in the history
Modify Get-PromptPath to return full dir when path is equal to $Home.
It will use ~ when path is in a subdir *under* $HOME.

This does not address other path shortening techniques.
We could do those in this PR or another one.

Fixes #565
  • Loading branch information
rkeithhill committed Apr 20, 2018
1 parent 554b881 commit 56446d1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/PoshGitTypes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class PoshGitPromptSettings {
[string[]]$RepositoriesInWhichToDisableFileStatus = @()

[string]$DescribeStyle = ''
[psobject]$WindowTitle = {param($GitStatus, [bool]$IsAdmin) "$(if ($IsAdmin) {'Administrator: '})$(if ($GitStatus) {"posh~git ~ $($GitStatus.RepoName) [$($GitStatus.Branch)] ~ "})PowerShell $($PSVersionTable.PSVersion) $([IntPtr]::Size * 8)-bit ($PID)"}
[psobject]$WindowTitle = {param($GitStatus, [bool]$IsAdmin) "$(if ($IsAdmin) {'Admin: '})$(if ($GitStatus) {"$($GitStatus.RepoName) [$($GitStatus.Branch)]"} else {Get-PromptPath}) - PowerShell $($PSVersionTable.PSVersion) $([IntPtr]::Size * 8)-bit ($PID)"}

[PoshGitTextSpan]$DefaultPromptPrefix = ''
[PoshGitTextSpan]$DefaultPromptPath = '$(Get-PromptPath)'
Expand Down
6 changes: 4 additions & 2 deletions src/Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,10 @@ function Get-PromptPath {

$stringComparison = Get-PathStringComparison

# Abbreviate path by replacing beginning of path with ~ *iff* the path is in the user's home dir
if ($abbrevHomeDir -and $currentPath -and $currentPath.StartsWith($Home, $stringComparison)) {
# Abbreviate path by replacing beginning of path with ~ *iff* the path is under the user's home dir
if ($abbrevHomeDir -and $currentPath -and !$currentPath.Equals($Home, $stringComparison) -and
$currentPath.StartsWith($Home, $stringComparison)) {

$currentPath = "~" + $currentPath.SubString($Home.Length)
}

Expand Down

0 comments on commit 56446d1

Please sign in to comment.