Last active
October 16, 2023 14:45
-
-
Save Hashbrown777/79a6c9a1f77d08774afeb10d179f990f to your computer and use it in GitHub Desktop.
neat coloured prompt for powershell that shows `user@pcname:pwd\nwinsymbol>` where winsymbol changes between red and green if the last command resulted in an error or no
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
#let the user know the current user, machine, directory, and success status of last command | |
$Script:prompt = '>' | |
function Prompt { | |
$error = !$? | |
Write-Host | |
Write-Host -NoNewline -ForegroundColor Yellow ([Environment]::UserName) | |
Write-Host -NoNewline '@' | |
Write-Host -NoNewline -ForegroundColor Cyan ([Environment]::MachineName) | |
Write-Host -NoNewline ':' | |
Write-Host -ForegroundColor Magenta $PWD.ProviderPath | |
Write-Host -NoNewline -ForegroundColor ('Green','Red')[$error] $Script:prompt | |
return [char]0x200B | |
} | |
#let the user know the OS being used | |
$Script:prompt = ` | |
if ($IsLinux) { | |
[char]0x25B6 | |
} | |
elseif ($IsMacOS) { | |
[char]0x2318 | |
} | |
elseif ($env:WT_SESSION) { | |
[char]0x2756 | |
} | |
else { | |
[char]0x2588 | |
} | |
#make sure user knows if they're in an elevated session | |
if ($(if ($IsLinux) { | |
#admin is not really a concept here because of sudoers file | |
$False | |
} | |
elseif ($IsMacOS) { | |
#TODO add full paths for commands so they *always* call the correct [default] binary | |
groups [Environment]::UserName | grep -q -w admin | Out-Null | |
!$? | |
} | |
else { | |
#current role | |
(New-Object Security.Principal.WindowsPrincipal( | |
[Security.Principal.WindowsIdentity]::GetCurrent() | |
#is admin? | |
)).IsInRole( | |
[Security.Principal.WindowsBuiltInRole]::Administrator | |
) | |
})) { | |
$Script:prompt = '!' + $Script:prompt | |
} |
#cd (lnk './bob.lnk')
Function lnk { Param($link)
gi ([io.path]::GetFullPath(
(New-Object -ComObject WScript.Shell).CreateShortcut(
(gi $link).FullName
).TargetPath
))
}
New-Alias -Name notepad++ -Value 'C:\Program Files\Notepad++\notepad++.exe'
(Get-PSReadLineOption).HistorySavePath
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$PROFILE.CurrentUserAllHosts