Skip to content

Instantly share code, notes, and snippets.

@Avellea
Last active January 6, 2023 03:10
Show Gist options
  • Save Avellea/e26b332ed35f70fd961d6f1273d79179 to your computer and use it in GitHub Desktop.
Save Avellea/e26b332ed35f70fd961d6f1273d79179 to your computer and use it in GitHub Desktop.
PowerShell prompt
# function prompt {
# $currentBranch = (&git rev-parse --abbrev-ref HEAD)
# # If we are in debug prompt
# if (test-path variable:/PSDebugContext) {
# Write-Host "[DBG] " -NoNewline -ForegroundColor Gray
# }
# if ($currentBranch) {
# Write-Host "[$currentBranch] " -NoNewline -ForegroundColor Cyan
# }
# # If terminal is run as administrator,
# # make username@hostname red. If not, green.
# # #/$
# # Displays `~` as the home directory when in C:\Users\<username>
# if([Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains 'S-1-5-32-544') {
# Write-Host "$env:UserName@$env:computername".ToLower() -NoNewLine -ForegroundColor red
# Write-Host ":" -NoNewLine -ForegroundColor Gray
# if($(Get-Location) -like "C:\Users\" + $env:UserName) {
# Write-Host "~" -NoNewLine -foregroundColor Blue
# } else {
# Write-Host "$(Get-Location)" -NoNewLine -ForegroundColor Blue
# }
# Write-Host "$('#' * ($nestedPromptLevel + 1))" -NoNewline -ForegroundColor White
# } else {
# Write-Host "$env:UserName@$env:computername".ToLower() -NoNewLine -ForegroundColor Green
# Write-Host ":" -NoNewLine -ForegroundColor Gray
# if($(Get-Location) -like "C:\Users\" + $env:UserName) {
# Write-Host "~" -NoNewLine -foregroundColor Blue
# } else {
# Write-Host "$(Get-Location)" -NoNewLine -ForegroundColor Blue
# }
# Write-Host "$('$' * ($nestedPromptLevel + 1))" -NoNewline -ForegroundColor White
# }
# return " "
# }
function prompt {
if([Security.Principal.WindowsIdentity]::GetCurrent().Groups -contains 'S-1-5-32-544') {
Write-Host "$env:computername".ToLower() -NoNewLine -ForegroundColor red
if($(Get-Location) -like "C:\Users\" + $env:UserName) {
Write-Host " ~" -NoNewLine -foregroundColor Blue
} else {
Write-Host " $(Get-Location)" -NoNewLine -ForegroundColor Blue
}
Write-Host "$(' #' * ($nestedPromptLevel + 1))" -NoNewline -ForegroundColor Blue
} else {
Write-Host "$env:computername".ToLower() -NoNewLine -ForegroundColor Green
if($(Get-Location) -like "C:\Users\" + $env:UserName) {
Write-Host " ~" -NoNewLine -foregroundColor Blue
} else {
Write-Host " $(Get-Location)" -NoNewLine -ForegroundColor Blue
}
Write-Host "$(' >' * ($nestedPromptLevel + 1))" -NoNewline -ForegroundColor Blue
}
return " "
}
# Opens the profile.ps1 in VSCode for editing
function global:PSProfile-Edit {
`code $profile`
}
# Reloads profile.ps1
function global:PSProfile-Reload {
& $profile
}
# Open current directory in explorer
function global:open {
PARAM (
[Parameter(Mandatory = $False, Position = 1)] [STRING] $dir
)
explorer.exe $dir
}
# Create an empty file
function global:touch {
PARAM (
[Parameter(Mandatory = $True, Position = 1)] [STRING] $file_name
)
New-Item ($file_name)
}
# Edit a file with TUI
function global:edit {
PARAM (
[Parameter(Mandatory = $True, Position = 1)] [STRING] $file_name
)
textadept-curses.exe ($file_name)
}
# Display ANSI console colors.
function Get-ConsoleColors {
[CmdletBinding()]
Param()
$List = [enum]::GetValues([System.ConsoleColor])
ForEach ($Color in $List){
Write-Host " $Color" -ForegroundColor $Color -NonewLine
Write-Host ""
}
ForEach ($Color in $List){
Write-Host " " -backgroundColor $Color -noNewLine
Write-Host " $Color"
}
}
function ver {
$PSVersionTable
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment