--[ modifed: profile.ps1 ]------------------------

+ Fixed powershell git status (now look exactly like zsh)
This commit is contained in:
ziro 2020-07-27 15:08:44 +07:00
parent 9952e0166d
commit 255b5cc69c

View file

@ -1,8 +1,12 @@
# ----- Messy function to make it looks like my zsh theme
function Git-Status function Git-Status
{ {
"$([char]27)[31m" "$([char]27)[31m"
if ((git status --porcelain -b 2>$1 | Select-String -Pattern 'M ') -notmatch 'fatal') { if ((git status --porcelain -b 2>$1 | Select-String -Pattern 'M ') -notmatch 'fatal') {
"M" "!"
}
if ((git status --porcelain -b 2>$1 | Select-String -Pattern '\# ') -notmatch 'fatal') {
""
} }
if ((git status --porcelain -b 2>$1 | Select-String -Pattern '\? ') -notmatch 'fatal') { if ((git status --porcelain -b 2>$1 | Select-String -Pattern '\? ') -notmatch 'fatal') {
"?" "?"
@ -12,20 +16,26 @@ function Git-Branch
{ {
" $([char]27)[35m " + (git branch --show-current) " $([char]27)[35m " + (git branch --show-current)
} }
function getdir
{
((Get-Location) -replace '/home/[a-zA-Z]*','~')
}
function end_of_prompt function end_of_prompt
{ {
" "
$([char]27)[32;1m$> $([char]27)[0m" $([char]27)[32;1m$> $([char]27)[0m"
} }
# ----- Foreground (the thing that actually shows up)
function prompt function prompt
{ {
if ((git log -n 1 2>$1) -notmatch 'fatal') { if ((git log -n 1 2>$1) -notmatch 'fatal') {
" "
$([char]27)[34;1m" + $env:COMPUTERNAME + "" + (Get-Location) + (Git-Branch) + (Git-Status) + (end_of_prompt) $([char]27)[34;1m" + $env:COMPUTERNAME + "" + (getdir) + (Git-Branch) + " " + ("$(Git-Status)" -replace ' ','') + (end_of_prompt)
} }
else else
{ {
" "
$([char]27)[34;1m" + $env:COMPUTERNAME + "" + (Get-Location) + (end_of_prompt) $([char]27)[34;1m" + $env:COMPUTERNAME + "" + (getdir) + (end_of_prompt)
} }
} }