-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
Feature request: Add a setting for the AdminText prefix in window title #537
Comments
You can do that with your own custom prompt function. Here is mine: function prompt {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = [Security.Principal.WindowsPrincipal] $identity
$name = ($identity.Name -split '\\')[1]
$path = Convert-Path $executionContext.SessionState.Path.CurrentLocation
$prefix = "($env:PROCESSOR_ARCHITECTURE)"
if($principal.IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) { $prefix = "Admin: $prefix" }
$realLASTEXITCODE = $LASTEXITCODE
$prefix = "Git $prefix"
Write-Host ("$prefix[$Name]") -nonewline
Write-VcsStatus
("`n$('+' * (get-location -stack).count)") + "PS $($path)$('>' * ($nestedPromptLevel + 1)) "
$global:LASTEXITCODE = $realLASTEXITCODE
$host.ui.RawUI.WindowTitle = "$prefix[$Name] $($path)"
}
|
You can also disable |
@sdwheeler , @rkeithhill , understood. I like most of the default settings of the posh prompt, and would rather not have to maintain my own prompt code. I think a new setting would be low-friction and easy to discover. It's a small change- here's the PR: #538 |
While pondering the proposed setting name ( EnableWindowTitle = $true
WindowTitlePrefix = 'posh~git ~ '
WindowTitleAdminPrefix = 'Administrator: posh~git ~ ' To avoid a breaking change, the logic would roughly be:
Come to think of it, instead of restricting title updated to a Git context, we could just turn this into a generic dynamic title mechanism, like the prompt (since #520), e.g. $global:GitPromptSettings = [pscustomobject]@{
...
EnableWindowTitle = 'posh~git ~' # stop supporting string in v1?
WindowTitlePrefix = ''
WindowTitleAdminPrefix = 'Administrator: '
WindowTitle = '$(Get-WindowTitle)'
}
function Get-WindowTitle {
$s = $Global:GitPromptSettings
$status = $Global:GitStatus
if (!$s -or !$status) { return 'PowerShell' }
$repoName = Split-Path -Leaf (Split-Path $status.GitDir)
$prefix = if ($s.EnableWindowTitle -is [string]) { $s.EnableWindowTitle } else { '' }
return "$prefix$repoName [$($status.Branch)]"
} To customize the title you'd replace Thoughts? |
Yup, this is one reason I was hesitating a bit on this. Also, we could make the setting take an expandable string like we do for DefaultPromptPrefix/Suffix as well as a ScriptBlock for more significant modifications. |
We could tweak this for 1.0. I've always thought it a bit weird that $GitPromptSettings.WindowTitle = {
param($GitStatus)
"$(if ($GitPromptSettings.IsAdmin) {"Admin "})posh~git ~ $($GitStatus.Repo) [$($GitStatus.Branch)]"
} A couple of things here. First, by using a scriptblock that takes the Git status object, we make it easy to inject the "current" status object. Or I guess the user could just use the global variable $GitPromptSettings.WindowTitle = {
param($GitStatus)
"$(if ($GitStatus.IsAdmin) {"Admin "})posh~git ~ $($GitStatus.Repo) [$($GitStatus.Branch)]"
} BTW why is it |
Would 1.0 support string or ScriptBlock? Seems like we need to pick one. Apart from the global dependency (which is well established posh-git behavior), there doesn't really seem to be much of a difference? The ScriptBlock can essentially live inside We also need to weigh customizability of the default title behavior vs letting/making folks replace the logic entirely. The |
We could make the property be of type [string], [scriptblock] or [psobject]. In the latter case, the user could supply a string or a scriptblock (that would return a string). The one nice thing about a scriptblock is that you don't have to worry about early interpolation of variables. I've helped a couple of folks with their RE customizability vs full replacement, that depends on how complex the default impl is. If it is simple enough (ideally a one-liner) then customization is still pretty easy. In this case: $GitPromptSettings.WindowTitle = {"posh~git ~ $($GitStatus.Repo) [$($GitStatus.Branch)] $(if ($GitStatus.IsAdmin) {"admin"})" Also FWIW I tend to like a lot of other types of info in my Window title: PSVersion, (x86/x64) and $PID - the latter is especially handy when I need to attach the debugger. Thanks for the pointer to the Console2 bug. |
OK, so my proposal: v0
@nebosite I feel like you stumbled on a bit more than you bargained for here. Let us know if you'd like to give this a go. v1
|
Sounds reasonable. I'll tackle the v1 changes tonight. |
I'm probably too crunched for time to make these changes without screwing something up. :( |
That's why we have code review. 😀 But seriously, thanks for suggesting the feature and proposing a fix - the project is better off for it. 🥂 |
Haha! Of course! I really love posh-git, so I will try to keep contributing in the future. |
For v0.7.2 I've gone ahead and merged @nebosite's simple fix. If someone's bored, cares deeply about customizing their window title, and can't upgrade to posh-git v1, they're welcome to give the proposal in #537 (comment) a go. |
I dislike the "Administor: " prefix on the powershell window title because it makes it harder to determine the subject of a window when it is minimized. I usually have 3-6 powershell windows open, so this is important for my workflow.
I already have a commit with a fix for this. It's six-line change to add the setting as well as move the $adminHeader calculation to the bottom of Write-GitStatus where the other window title logic is located.
The text was updated successfully, but these errors were encountered: