Skip to content

Commit

Permalink
Improving performance by removing directory
Browse files Browse the repository at this point in the history
  • Loading branch information
saleh-rahimzadeh committed Jul 18, 2019
1 parent 58d96df commit 38eafc0
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions GoodPrompt.ps1
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
<#----------------------------------------------------------------------------#
# GoodPrompt #
# Version 1.2 #
# Version 1.3 #
# Copyright (C) Saleh Rahimzadeh #
# https://github.com/saleh-rahimzadeh/GoodPrompt #
#----------------------------------------------------------------------------#>

function Prompt {
<# Preparing details and information of prompt as a data dictionary #>
$data = @{
Path = '{0} {1}>' -f "`u{2592}",$($ExecutionContext.SessionState.Path.CurrentLocation);
Status = '{0}{1} {2} {3} ' -f $(if (test-path variable:/PSDebugContext) { '[DBG] {0} ' -f "`u{2502}" } else { '' }), (get-date -uformat %r), "`u{2502}", $MyInvocation.HistoryId;
Bar = "`u{258c}";
Cursor = $(if ($host.UI.RawUI.WindowSize.Width -lt $host.UI.RawUI.MaxWindowSize.Width) { "`n" } else { '' }) + "`u{25ba}" * ($NestedPromptLevel + 1);
}
<# Preparing details and information of prompt #>
$Location = '{0} {1}>' -f "`u{2592}",$($ExecutionContext.SessionState.Path.CurrentLocation);
$Status = '{0}{1} {2} {3} ' -f $(if (Test-Path variable:/PSDebugContext) { '[DBG] {0} ' -f "`u{2502}" } else { '' }), (get-date -uformat %r), "`u{2502}", $MyInvocation.HistoryId;
$Bar = "`u{258c}";
$Cursor = $(if ($host.UI.RawUI.WindowSize.Width -lt $host.UI.RawUI.MaxWindowSize.Width) { "`n" } else { '' }) + "`u{25ba}" * ($NestedPromptLevel + 1);

<# Calculating remained space to draw separator bar #>
$space = $host.UI.RawUI.WindowSize.Width - (($data.Path.Length + $data.Bar.Length) % $host.UI.RawUI.WindowSize.Width) - $data.Status.Length
if ($space -lt 0) {
$space += $host.UI.RawUI.WindowSize.Width
$Space = $host.UI.RawUI.WindowSize.Width - (($Location.Length + $Bar.Length) % $host.UI.RawUI.WindowSize.Width) - $Status.Length
if ($Space -lt 0) {
$Space += $host.UI.RawUI.WindowSize.Width
if ($host.UI.RawUI.WindowSize.Width -lt $host.UI.RawUI.MaxWindowSize.Width) {
$space += ($host.UI.RawUI.MaxWindowSize.Width - $host.UI.RawUI.WindowSize.Width)
$Space += ($host.UI.RawUI.MaxWindowSize.Width - $host.UI.RawUI.WindowSize.Width)
}
}
$data.Bar += ' ' * $space
$Bar += ' ' * $Space

<# Display prompt #>
Write-Host $data.Path -ForegroundColor Black -BackgroundColor White -NoNewline
Write-Host $data.Bar -ForegroundColor Black -BackgroundColor DarkGray -NoNewLine
Write-Host $data.Status -ForegroundColor White -BackgroundColor DarkGray -NoNewLine
Write-Host $data.Cursor -ForegroundColor White -NoNewLine
Write-Host $Location -ForegroundColor Black -BackgroundColor White -NoNewline
Write-Host $Bar -ForegroundColor Black -BackgroundColor DarkGray -NoNewline
Write-Host $Status -ForegroundColor White -BackgroundColor DarkGray -NoNewline
Write-Host $Cursor -ForegroundColor White -NoNewline
return ' '
}

0 comments on commit 38eafc0

Please sign in to comment.