Skip to content

Instantly share code, notes, and snippets.

@crisleo94
Created August 14, 2021 09:35
Show Gist options
  • Save crisleo94/815a6461c25bf23efb51ed25942cbde8 to your computer and use it in GitHub Desktop.
Save crisleo94/815a6461c25bf23efb51ed25942cbde8 to your computer and use it in GitHub Desktop.
function prompt {
# get only last folder location
$p = Split-Path -leaf -path (Get-Location)
$user = $env:UserName
$host.UI.RawUI.WindowTitle = "@" + $user + "\" + $p + ">"
$host.UI.RawUI.ForegroundColor = "Blue"
# detect if the current folder is a git repository in order to show the branch
if (Test-Path .git) {
$p = Split-Path -leaf -path (Get-Location)
git branch | ForEach-Object {
if ($_ -match "^\*(.*)") {
$branch = $matches[1] + " ) "
Write-Host -NoNewLine $user -ForegroundColor Magenta
Write-Host -NoNewLine "@\"
Write-Host -NoNewLine $p -ForegroundColor Yellow
Write-Host -NoNewLine " (" -ForegroundColor DarkGreen
Write-Host -NoNewLine " branch:" -ForegroundColor DarkGreen
Write-Host -NoNewLine $branch -ForegroundColor DarkGreen
}
}
}
else {
Write-Host -NoNewLine $user -ForegroundColor Magenta
Write-Host -NoNewLine "@\"
Write-Host -NoNewLine $p -ForegroundColor Yellow
Write-Host -NoNewLine " " -ForegroundColor Black
}
# checks if you're in a virtual python env and displays it
if ($env:PIPENV_ACTIVE -eq 1) {
# @TODO: works only on Windows
$venv = (($env:VIRTUAL_ENV -split "\\")[-1] -split "-")[0] + ") "
Write-Host -NoNewLine "(" -ForegroundColor Cyan
Write-Host -NoNewLine "env:" -ForegroundColor Cyan
Write-Host -NoNewLine $venv -ForegroundColor Cyan
}
"> "
}
# git alias
function Get-Git { & git $args }
New-Alias -Name g -Value Get-Git -Force -Option AllScope
#to create new aliases that might require arguments in any context follow the same pattern
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment