Skip to content

Instantly share code, notes, and snippets.

@dam5s
Last active August 14, 2019 00:13
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 dam5s/4fbb59bbe516e8e0ccfeebc7bb30eb58 to your computer and use it in GitHub Desktop.
Save dam5s/4fbb59bbe516e8e0ccfeebc7bb30eb58 to your computer and use it in GitHub Desktop.
A custom Powershell prompt à la Oh My ZSH

How to setup

Assuming you have Visual studio code installed and on the path. Assuming you have git installed and on the path.

  1. Open PowerShell.
  2. Edit your profile
    code $profile
    
  3. Paste the content of the file below
  4. Save in UTF-8 with BOM encoding.
  5. Open a new PowerShell or source your new profile
    . $profile
    
function PromptFolder {
$currentFolder = $(Get-Item -Path "./")
$isHome = $currentFolder.FullName -eq $HOME
$folderName =
if ($isHome) { "~" }
else { $currentFolder.Name }
$host.ui.RawUI.WindowTitle = $folderName
Write-Host $folderName -NoNewline -ForegroundColor Cyan
}
function PromptGitBranch {
$gitBranch = $(git rev-parse --abbrev-ref HEAD)
if ($gitBranch) {
Write-Host " git:(" -NoNewline -ForegroundColor Blue
Write-Host $gitBranch -NoNewline -ForegroundColor DarkRed
Write-Host ")" -NoNewline -ForegroundColor Blue
$changedFiles = $(git status --porcelain)
if ($changedFiles) {
Write-Host " ✗" -NoNewline -ForegroundColor Yellow
}
}
}
function Prompt {
if ($?) { Write-Host "➜ " -NoNewline -ForegroundColor Green }
else { Write-Host "➜ " -NoNewline -ForegroundColor Red }
PromptFolder;
PromptGitBranch;
return " "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment