Merge pull request #1 from ian-craig/status-branchonly

Status branchonly
This commit is contained in:
Chris Antos 2021-05-31 20:38:23 -07:00 committed by GitHub
commit 6730f864b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 21 deletions

14
vendor/clink.lua vendored
View File

@ -41,6 +41,10 @@ local function get_conflict_color()
return conflict_color or "\x1b[31;1m" return conflict_color or "\x1b[31;1m"
end end
local function get_unknown_color()
return unknown_color or "\x1b[30;1m"
end
--- ---
-- Makes a string safe to use as the replacement in string.gsub -- Makes a string safe to use as the replacement in string.gsub
--- ---
@ -392,17 +396,19 @@ local function git_prompt_filter()
local colors = { local colors = {
clean = get_clean_color(), clean = get_clean_color(),
dirty = get_dirty_color(), dirty = get_dirty_color(),
conflict = get_conflict_color() conflict = get_conflict_color(),
unknown = get_unknown_color()
} }
local git_dir = get_git_dir() local git_dir = get_git_dir()
cmderGitStatusOptIn = get_git_status_setting() cmderGitStatusOptIn = get_git_status_setting()
if cmderGitStatusOptIn then
if git_dir then if git_dir then
-- if we're inside of git repo then try to detect current branch -- if we're inside of git repo then try to detect current branch
local branch = get_git_branch(git_dir) local branch = get_git_branch(git_dir)
local color local color = colors.unknown
if branch then if branch then
if cmderGitStatusOptIn then
-- Has branch => therefore it is a git folder, now figure out status -- Has branch => therefore it is a git folder, now figure out status
local gitStatus = get_git_status() local gitStatus = get_git_status()
local gitConflict = get_git_conflict() local gitConflict = get_git_conflict()
@ -415,12 +421,12 @@ local function git_prompt_filter()
if gitConflict then if gitConflict then
color = colors.conflict color = colors.conflict
end end
end
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")")
return false return false
end end
end end
end
-- No git present or not in git file -- No git present or not in git file
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "") clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "")

View File

@ -43,3 +43,4 @@ lamb_color = "\x1b[1;30;40m" -- Light Grey = Lambda Color
clean_color = "\x1b[1;37;40m" clean_color = "\x1b[1;37;40m"
dirty_color = "\x1b[33;3m" dirty_color = "\x1b[33;3m"
conflict_color = "\x1b[31;1m" conflict_color = "\x1b[31;1m"
unknown_color = "\x1b[30;1m"

18
vendor/git-prompt.sh vendored
View File

@ -9,6 +9,21 @@ function getGitStatusSetting() {
fi 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 if test -f /etc/profile.d/git-sdk.sh
then then
TITLEPREFIX=SDK-${MSYSTEM#MINGW} TITLEPREFIX=SDK-${MSYSTEM#MINGW}
@ -45,6 +60,9 @@ else
. "$COMPLETION_PATH/git-prompt.sh" . "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[36m\]' # change color to cyan PS1="$PS1"'\[\033[36m\]' # change color to cyan
PS1="$PS1"'`__git_ps1`' # bash function PS1="$PS1"'`__git_ps1`' # bash function
else
PS1="$PS1"'\[\033[30;1m\]' # change color to gray
PS1="$PS1"'`getSimpleGitBranch`'
fi fi
fi fi
fi fi

View File

@ -36,6 +36,14 @@ function checkGit($Path) {
if (getGitStatusSetting -eq $true) { if (getGitStatusSetting -eq $true) {
Write-VcsStatus 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 return