Skip to content

Instantly share code, notes, and snippets.

@MRezaSafari
Last active November 5, 2021 22:33
Show Gist options
  • Save MRezaSafari/c8a345decf57af855c00d218718b87bb to your computer and use it in GitHub Desktop.
Save MRezaSafari/c8a345decf57af855c00d218718b87bb to your computer and use it in GitHub Desktop.
my preferred powerline settings using Matheus Castello code
# 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