Skip to content

Instantly share code, notes, and snippets.

@jcoutch
Last active May 8, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcoutch/b90fbeca11c118481a43b3cd38dc0f9c to your computer and use it in GitHub Desktop.
Save jcoutch/b90fbeca11c118481a43b3cd38dc0f9c to your computer and use it in GitHub Desktop.
PowerShell profile for changing window titles based on folder name and elevation status
# This script overrides the default prompt behavior, and sets the title of the window to something like this:
# (admin) PS: current_folder_name
#
# To apply to your profile, open a PowerShell window and type:
#
# Windows: notepad $PROFILE
# Mac/Linux: vi $PROFILE
function Test-Administrator
{
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
# Overrides the default prompt behavior
function Prompt
{
If(Test-Administrator) {
$userName = 'admin'
} else {
$userName = $env:USERNAME
}
$location = Get-Item (Get-Location)
$host.ui.RawUI.WindowTitle = "($userName) PS: $($location.Name)"
"PS $($location.FullName)>"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment