Skip to content

Instantly share code, notes, and snippets.

@elephantatech
Last active August 19, 2020 22:24
Show Gist options
  • Save elephantatech/61384b07139a4a9a89f2c4b79f6035c9 to your computer and use it in GitHub Desktop.
Save elephantatech/61384b07139a4a9a89f2c4b79f6035c9 to your computer and use it in GitHub Desktop.
my powershell prompt
# edit the $PROFILE using command with vscode on windows
# #> code $PROFILE
# first time you edit it will save on C:\Users\[your username]\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
# you can also create it manually as well.
# following will create prompt with the following style
# [2020-08-19 18:20:56] ~>
# #>
#
# $ before > means you are on session with admin rights
# [2020-08-19 18:24:05] ~\Documents\GitHub>
# $>
#
#
# get Parameters needed
# set varable Admin with # for non admin users
$Global:Admin="#"
# Current user name
$CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
# get current user properties
$principal = new-object System.Security.principal.windowsprincipal($CurrentUser)
# check if current user is an admin
# if he is the change Admin to $ for Super user like bash does
if ($principal.IsInRole("Administrators"))
{
$Admin="$"
}
# prompt for powershell
function global:prompt {
$host.ui.rawui.WindowTitle = $CurrentUser.Name + " "+ $Host.Version + " Line: " + $host.UI.RawUI.CursorPosition.Y
$regex = [regex]::Escape($HOME) + "(\\.*)*$"
write-host "[$($(get-date).Tostring("yyyy-MM-dd HH:mm:ss"))] $($executionContext.SessionState.Path.CurrentLocation.Path -replace $regex, '~$1')$('>' * ($nestedPromptLevel + 1)) ";
return "$Admin> "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment