-
-
Notifications
You must be signed in to change notification settings - Fork 823
Rename tabs to match the repo and branch when in powershell ise #605
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
0fb0b9a
fc5dec1
b8d0042
b1b7393
24ee260
d1ab53e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,3 +58,45 @@ function Set-WindowTitle { | |
| } | ||
| } | ||
| } | ||
|
|
||
| function Set-TabTitle { | ||
|
||
| [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] | ||
| param($GitStatus) | ||
| $settings = $global:GitPromptSettings | ||
|
|
||
| if ($settings.TabTitle == $false) { | ||
| return | ||
| } | ||
|
|
||
| # If the user is running Powershell ISE then name the tab | ||
| if($psISE -and $GitStatus){ | ||
|
||
| $existingTabNames = $psISE.PowerShellTabs | % {$_.DisplayName} | ||
| $currentTabName = $psise.CurrentPowerShellTab.DisplayName | ||
| $tabName = Get-TabTitle $GitStatus $existingTabNames $currentTabName | ||
| $psise.CurrentPowerShellTab.DisplayName = $tabName | ||
| } | ||
| } | ||
|
|
||
| function Get-TabTitle { | ||
|
||
| [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] | ||
| param($GitStatus, [string[]]$existingTabNames, [string]$currentTabName) | ||
|
|
||
| $repo = $GitStatus.RepoName | ||
| $branch = $GitStatus.Branch | ||
| $tabName = "$repo [$branch]" | ||
| #you can't have 2 tabs with the same name so shove a number on the end | ||
| $tabCount = 0 | ||
| foreach($existingTabName in $existingTabNames){ | ||
| if($existingTabName.StartsWith($tabName) -and $existingTabName -ne $currentTabName){ | ||
| $tabCount++ | ||
| $tabNumber = [int]$existingTabName.Replace($tabName, "").Replace("(", "").Replace(")", "").Trim() | ||
| if($tabCount -lt $tabNumber + 1){ | ||
| $tabCount = $tabNumber + 1 | ||
| } | ||
| } | ||
| } | ||
| if($tabCount -gt 0){ | ||
| $tabName= "$tabName ($tabCount)" | ||
| } | ||
| return $tabName | ||
| } | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ $GitPromptScriptBlock = { | |
|
|
||
| # This has to be *after* the call to Write-VcsStatus, which populates $global:GitStatus | ||
| Set-WindowTitle $global:GitStatus $IsAdmin | ||
| Set-TabTitle $global:GitStatus | ||
|
||
|
|
||
| # If prompt timing enabled, write elapsed milliseconds | ||
| if ($settings.DefaultPromptEnableTiming) { | ||
|
|
||



There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider following the pattern that
$WindowTitleuses. By specifying a scriptblock, users will be able to easily customize the text that gets put in the tab title. To simplify the scriptblock, you can use functions. Perhaps aGet-UniqueTabTitleto handle the logic for appending a number to the title to make it unique. Perhaps it would be something like this: