Last active
May 8, 2019 15:52
-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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