Skip to content

Instantly share code, notes, and snippets.

@Keimeno
Created August 8, 2021 11:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keimeno/88be5a3d2d0cb8e623021cd8663b765d to your computer and use it in GitHub Desktop.
Save Keimeno/88be5a3d2d0cb8e623021cd8663b765d to your computer and use it in GitHub Desktop.
My Powershell Profile
$path = Get-Location
if ($path -Match 'C:\\WINDOWS\\system32') {
Set-Location $ENV:UserProfile
}
Clear-Host
Write-Host 'Powershell' $PsVersionTable.PSVersion
Write-Host "Don't forget to git commit & git push before leaving a burning building."
Write-Host ''
function pull {
Pull-Current
}
function push {
Push-Current
}
function Pull-Current {
$branch = git rev-parse --abbrev-ref HEAD
if ($branch -ne "HEAD") {
Write-Host "Pulling..."
git pull origin $branch
Write-Host "Successfully pulled from" -NoNewline
Write-Host " $branch" -NoNewline -ForegroundColor "green"
Write-Host "." -NoNewline
}
}
function Push-Current {
$branch = git rev-parse --abbrev-ref HEAD
if ($branch -ne "HEAD") {
Write-Host "Pushing..."
git push origin $branch
Write-Host "Successfully pushed" -NoNewline
Write-Host " $branch" -NoNewline -ForegroundColor "green"
Write-Host " to origin." -NoNewline
}
}
function Write-BranchName {
try {
$branch = git rev-parse --abbrev-ref HEAD
if ($branch -eq "HEAD") {
# we're probably in detached HEAD state, so print the SHA
$branch = git rev-parse --short HEAD
Write-Host "$branch" -NoNewline -ForegroundColor "red"
}
else {
# we're on an actual branch, so print it
Write-Host "$branch" -NoNewline -ForegroundColor "green"
}
} catch {
# we'll end up here if we're in a newly initiated git repo
Write-Host "no branches yet" -NoNewline -ForegroundColor "yellow"
}
}
function prompt {
$base = "PS "
$path = "$($executionContext.SessionState.Path.CurrentLocation)"
$userPrompt = "$('>' * ($nestedPromptLevel + 1)) "
Write-Host "$base" -NoNewline -ForegroundColor "blue"
if (Test-Path .git) {
Write-Host $path -NoNewline -ForegroundColor "white"
Write-Host " [" -NoNewline -ForegroundColor "darkgray"
Write-BranchName
Write-Host "]" -ForegroundColor "darkgray"
}
else {
# we're not in a repo so don't bother displaying branch name/sha
Write-Host $path -ForegroundColor "gray"
}
return $userPrompt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment