Advertisement
Guest User

Untitled

a guest
Mar 16th, 2015
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function prompt
  2. {
  3.     Set-StrictMode -Off
  4.  
  5.     $history = Get-History
  6.     $nextHistoryId = $history.Count + 1
  7.     Write-Host "[" -ForegroundColor DarkGray -NoNewline
  8.     Write-Host "$nextHistoryId" -ForegroundColor Red -NoNewline
  9.     Write-Host "|" -ForegroundColor DarkGray -NoNewline
  10.  
  11.     Write-Host "$((Get-Date).ToShortTimeString())" -ForegroundColor Yellow -NoNewline
  12.  
  13.     if ($history) {
  14.         $timing = $history[-1].EndExecutionTime - $history[-1].StartExecutionTime
  15.         Write-Host "|" -ForegroundColor DarkGray -NoNewline
  16.  
  17.         $color = "Green"
  18.         if ($timing.TotalSeconds -gt 1) {
  19.             $color = "Red"
  20.         }
  21.  
  22.         Write-Host "+" -ForegroundColor $color -NoNewline
  23.         if ($timing.Hours) { Write-Host "$(($timing).Hours)h " -ForegroundColor $color -NoNewline }
  24.         if ($timing.Minutes) { Write-Host "$(($timing).Minutes)m " -ForegroundColor $color -NoNewline }
  25.         if ($timing.Seconds) { Write-Host "$(($timing).Seconds)s " -ForegroundColor $color -NoNewline }
  26.         Write-Host "$(($timing).Milliseconds)ms" -ForegroundColor $color -NoNewline
  27.     }
  28.  
  29.     Write-Host "] " -ForegroundColor DarkGray -NoNewline
  30.    
  31.     Write-Host "[" -ForegroundColor DarkGray -NoNewline
  32.    
  33.     [string]$path = $Pwd.Path
  34.  
  35.     if ($path -like "c:\users\$env:username*") {
  36.         $path = "~home" + $path.Substring("c:\users\$env:username".Length)
  37.     }
  38.  
  39.     $chunks = $path -split '\\'
  40.  
  41.     $short = $false
  42.     if ($Pwd.Path.Length -gt 30 -and $chunks.Length -gt 2) {
  43.         $chunks = $chunks | select -Last 2
  44.         $short = $true
  45.     }
  46.  
  47.     if ($short) {
  48.         Write-Host "...\" -ForegroundColor DarkGray -NoNewline
  49.     }
  50.  
  51.     $chunks | % { $i = 0 } {
  52.         $i++
  53.         $color = "Yellow"
  54.  
  55.         if ($_ -like "~home") { $color = "Green" }
  56.         Write-Host "$_" -ForegroundColor $color -NoNewline
  57.  
  58.         if ($i -le $chunks.Count-1) {
  59.             Write-Host "\" -ForegroundColor DarkGray -NoNewline
  60.         }
  61.     }
  62.  
  63.     Write-Host "]" -ForegroundColor DarkGray -NoNewline
  64.      
  65.  
  66.     $g = Get-GitStatus
  67.  
  68.     if ($g) {
  69.         Write-Host " [" -ForegroundColor DarkGray -NoNewline
  70.        
  71.         $branch = $g.Branch.Split("...") | select -first 1
  72.         Write-Host $branch -ForegroundColor Red -NoNewline
  73.  
  74.         $add = $g.Working.Added.Count
  75.         $cha = $g.Working.Modified.Count
  76.         $del = $g.Working.Deleted.Count
  77.         $ahead = $g.AheadBy
  78.         $behind = $g.BehindBy
  79.  
  80.         if ($add) {
  81.             Write-Host "|" -ForegroundColor DarkGray -NoNewline
  82.             Write-Host "+$add" -ForegroundColor Yellow -NoNewline
  83.         }
  84.  
  85.         if ($rem) {
  86.             Write-Host "|" -ForegroundColor DarkGray -NoNewline
  87.             Write-Host "-$rem" -ForegroundColor Yellow -NoNewline
  88.         }
  89.  
  90.         if ($cha) {
  91.             Write-Host "|" -ForegroundColor DarkGray -NoNewline
  92.             Write-Host "~$cha" -ForegroundColor Yellow -NoNewline
  93.         }
  94.  
  95.         if (!$g.Working) {
  96.             Write-Host "|" -ForegroundColor DarkGray -NoNewline
  97.             Write-Host "clean" -ForegroundColor Green -NoNewline
  98.         }
  99.  
  100.         if ($ahead) {
  101.             Write-Host "|" -ForegroundColor DarkGray -NoNewline
  102.             Write-Host "▲$ahead" -ForegroundColor Green -NoNewline
  103.         }
  104.  
  105.         if ($behind) {
  106.             Write-Host "|" -ForegroundColor DarkGray -NoNewline
  107.             Write-Host "▼$behind" -ForegroundColor Red -NoNewline
  108.         }
  109.  
  110.         Write-Host "]" -ForegroundColor DarkGray -NoNewline
  111.     }
  112.     Write-Host "`n>" -ForegroundColor DarkGray -NoNewline
  113.     return " "
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement