Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Last active October 16, 2023 14:45
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 Hashbrown777/79a6c9a1f77d08774afeb10d179f990f to your computer and use it in GitHub Desktop.
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
#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
}
@Hashbrown777
Copy link
Author

Hashbrown777 commented Jun 23, 2023

$PROFILE.CurrentUserAllHosts

@Hashbrown777
Copy link
Author

Hashbrown777 commented Jul 31, 2023

#cd (lnk './bob.lnk')
Function lnk { Param($link)
    gi ([io.path]::GetFullPath(
        (New-Object -ComObject WScript.Shell).CreateShortcut(
            (gi $link).FullName
        ).TargetPath
    ))
}

@Hashbrown777
Copy link
Author

New-Alias -Name notepad++ -Value 'C:\Program Files\Notepad++\notepad++.exe'

@Hashbrown777
Copy link
Author

(Get-PSReadLineOption).HistorySavePath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment