Last active
November 5, 2021 22:33
-
-
Save MRezaSafari/c8a345decf57af855c00d218718b87bb to your computer and use it in GitHub Desktop.
my preferred powerline settings using Matheus Castello code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install-Module PANSIES -AllowClobber | |
# Install-Module PowerLine | |
# lets set the powerline in this profile | |
Import-Module PowerLine | |
# aux variables | |
$ERRORS_COUNT = 0 | |
$ERROR_EMOJI = "π", "π΅", "π₯΄", "π", "π±", "π‘", "π€¬", "π", "π€", "π", ` | |
"π₯Ί", "π«", "π", "π©", "π°" | |
$global:EC = 0 | |
$global:EXIT_CODE = 0 | |
# clear the last win32 exit code | |
$global:LASTEXITCODE = 0 | |
# set my powerline blocks | |
[System.Collections.Generic.List[ScriptBlock]]$Prompt = @( | |
# my current path | |
{ | |
($executionContext.SessionState.Path.CurrentLocation) | |
} | |
# git branch and cmd error check | |
{ | |
$EC = $global:EC | |
$ERRORS_COUNT = $global:EXIT_CODE | |
# execute git to check current branch | |
$gitRet = git rev-parse --abbrev-ref HEAD | |
if ( $EC -gt $ERRORS_COUNT -or $EXIT_CODE -ne 0) { | |
$ERRORS_COUNT = $EC | |
if ( $gitRet ) { | |
"  $gitRet " | |
$Global:Prompt.Colors[3] = "Blue" | |
# not git repo and the last cmd return a error | |
} else { | |
# get a ramdom emoji | |
$ERROR_EMOJI[(Get-Random -Maximum $ERROR_EMOJI.count)] | |
} | |
$Global:Prompt.Colors[3] = "Red" | |
$Global:Prompt.Colors[5] = "Red" | |
# not git repo and all clear | |
} else { | |
if ( $gitRet ) { | |
"  $gitRet " | |
$Global:Prompt.Colors[3] = "Gray" | |
# not git repo and the last cmd return a error | |
} | |
$Global:Prompt.Colors[3] = "Green" | |
$Global:Prompt.Colors[5] = "Gray" | |
} | |
# clear the errors and last exit code for the next interaction | |
$error.clear() | |
$global:LASTEXITCODE = 0 | |
} | |
# pipe | |
{ '' * ($nestedPromptLevel + 1) } | |
) | |
# execute | |
Set-PowerLinePrompt ` | |
-PowerLineFont ` | |
-SetCurrentDirectory ` | |
-RestoreVirtualTerminal ` | |
-HideError ` | |
-Colors "Gray", "Green", "Gray", "Green", "Blue", "Gray" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment