From a5c98d4fe92800a5f819c3f9393848311d908f88 Mon Sep 17 00:00:00 2001 From: Ian Craig Date: Tue, 25 May 2021 21:03:28 -0700 Subject: [PATCH] Add simple branch name gen for sh and ps1 --- vendor/git-prompt.sh | 18 ++++++++++++++++++ vendor/psmodules/Cmder.ps1 | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/vendor/git-prompt.sh b/vendor/git-prompt.sh index c41a5a1..ccda575 100644 --- a/vendor/git-prompt.sh +++ b/vendor/git-prompt.sh @@ -9,6 +9,21 @@ function getGitStatusSetting() { fi } +function getSimpleGitBranch() { + gitDir=$(git rev-parse --git-dir 2>/dev/null) + if [ -z "$gitDir" ]; then + return 0 + fi + + headContent=$(< "$gitDir/HEAD") + if [[ "$headContent" == "ref: refs/heads/"* ]] + then + echo " (${headContent:16})" + else + echo " (HEAD detached at ${headContent:0:7})" + fi +} + if test -f /etc/profile.d/git-sdk.sh then TITLEPREFIX=SDK-${MSYSTEM#MINGW} @@ -45,6 +60,9 @@ else . "$COMPLETION_PATH/git-prompt.sh" PS1="$PS1"'\[\033[36m\]' # change color to cyan PS1="$PS1"'`__git_ps1`' # bash function + else + PS1="$PS1"'\[\033[30;1m\]' # change color to gray + PS1="$PS1"'`getSimpleGitBranch`' fi fi fi diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 86dfb02..5ede0cf 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -36,6 +36,14 @@ function checkGit($Path) { if (getGitStatusSetting -eq $true) { Write-VcsStatus + } else { + $headContent = Get-Content (Join-Path $Path '.git/HEAD') + if ($headContent -like "ref: refs/heads/*") { + $branchName = $headContent.Substring(16) + } else { + $branchName = "HEAD detached at $($headContent.Substring(0, 7))" + } + Write-Host " [$branchName]" -NoNewline -ForegroundColor DarkGray } return