Guest User

Untitled

a guest
Jan 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. Import-Module Get-ChildItemColor
  2.  
  3. if ( -not $env:ConEmuPID ) {
  4. function global:prompt {
  5. -join($(
  6. if (test-isadmin) {"λ "}),"$($env:username.ToUpper()) ►► ")
  7. }
  8. }
  9. else {
  10. $ColorSuffix = 'm'
  11. $global:ColorTimestamp = @(
  12. 15,
  13. 7,
  14. 0
  15. )
  16. $global:ColorTimestamp = $($global:ColorTimestamp | % {
  17. -join($_,$ColorSuffix)
  18. })
  19.  
  20. $global:ColorPrompt =@(
  21. 117,
  22. 1,
  23. 3,
  24. 22,
  25. 5,
  26. 20
  27. )
  28.  
  29. $global:ColorPrompt = [System.Collections.ArrayList]$($global:ColorPrompt | % {
  30. -join($_,$ColorSuffix)
  31. })
  32.  
  33. $TextColor = -join('$F;',15,$ColorSuffix)
  34. $BackgroundColor = -join('$B;','$($ColorPrompt[$ColorIndex])')
  35. $SeperatorBase = """$(-join('$B;','$($ColorPrompt[$ColorIndex + 1])'))$(-join('$F;','$($ColorPrompt[$ColorIndex])')){0}"""
  36. $seperator = [scriptblock]::Create("$SeperatorBase -f ''")
  37. $ItemBaseString = """$BackgroundColor$TextColor{0}"
  38.  
  39. [System.Collections.Generic.List[ScriptBlock]]$Global:TimestampEntries = @(
  40. {" " * ($Host.UI.RawUI.BufferSize.Width - 29) }
  41. {"$F;${er}m{0}" -f [char]0xe0b2 }
  42. {"$F;$($ColorTimestamp[$TimestampIndex])$B;${er}m{0}" -f $(if (@(get-history).Count -gt 0){(get-history)[-1] | % { "{0:c}" -f (new-timespan $_.StartExecutionTime $_.EndExecutionTime)}}else{'00:00:00.0000000'}) }
  43.  
  44. {"$F;$($ColorTimestamp[$TimestampIndex])$B;${er}m{0}" -f [char]0xe0b2 }
  45. {"$F;$($ColorTimestamp[$TimestampIndex])$B;$($ColorTimestamp[$TimestampIndex - 1]){0}" -f $(get-date -format "hh:mm:ss tt") }
  46. )
  47.  
  48. [System.Collections.Generic.List[ScriptBlock]]$Global:PromptEntries = @(
  49. "$ItemBaseString"" -f `$('{0:d4}' -f `$MyInvocation.HistoryId)",
  50. "$ItemBaseString"" -f `$([char]5122)",
  51. "$ItemBaseString"" -f `$(`$env:username.ToUpper())",
  52. "$ItemBaseString"" -f `$(if(`$pushd = (Get-Location -Stack).count) { ""`$([char]187)"" + `$pushd })",
  53. "$ItemBaseString"" -f `$(`$pwd.Drive.Name)",
  54. "$ItemBaseString`$E[0m"" -f `$(Split-Path `$pwd -leaf)"
  55. ) | %{[scriptblock]::Create($_);$seperator}
  56.  
  57. $Global:PromptEntries[-1] = { "$F;20m{0} $E[0m" -f $([char]0xe0b0) }
  58.  
  59. if( -not ( Test-IsAdmin )) {
  60. $Global:PromptEntries.RemoveRange(2,2)
  61. $ColorPrompt.RemoveAt(1)
  62. }
  63.  
  64.  
  65.  
  66. function global:prompt {
  67. $global:er = if ($?){22}else{1}
  68. $E = "$([char]27)"
  69. $F = "$E[38;5"
  70. $B = "$E[48;5"
  71. -join(
  72. (
  73. -join$(
  74. 0..($Global:TimestampEntries.Count - 1) | %{
  75. $TimestampIndex = $_ - 2
  76. ($Global:TimestampEntries[$_].Invoke())
  77. }
  78. )
  79. ),
  80. (
  81. -join$(
  82. 0..($Global:PromptEntries.Count - 1) | %{
  83. $ColorIndex = [math]::Floor($_/2)
  84. ($Global:PromptEntries[$_].Invoke())
  85. }
  86. )
  87. )
  88. )
  89. }
  90. }
  91.  
  92. Import-Module Get-ChildItemColor
  93.  
  94. Set-Alias l Get-ChildItemColor -option AllScope
  95. Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
  96. Set-Alias dir Get-ChildItemColor -option AllScope -Force
Add Comment
Please, Sign In to add comment