Skip to content

Commit 6730f86

Browse files
authored
Merge pull request #1 from ian-craig/status-branchonly
Status branchonly
2 parents 36f4ce0 + a5c98d4 commit 6730f86

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

Diff for: vendor/clink.lua

+30-24
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ local function get_conflict_color()
4141
return conflict_color or "\x1b[31;1m"
4242
end
4343

44+
local function get_unknown_color()
45+
return unknown_color or "\x1b[30;1m"
46+
end
47+
4448
---
4549
-- Makes a string safe to use as the replacement in string.gsub
4650
---
@@ -392,34 +396,36 @@ local function git_prompt_filter()
392396
local colors = {
393397
clean = get_clean_color(),
394398
dirty = get_dirty_color(),
395-
conflict = get_conflict_color()
399+
conflict = get_conflict_color(),
400+
unknown = get_unknown_color()
396401
}
397402

398403
local git_dir = get_git_dir()
399404
cmderGitStatusOptIn = get_git_status_setting()
400-
if cmderGitStatusOptIn then
401-
if git_dir then
402-
-- if we're inside of git repo then try to detect current branch
403-
local branch = get_git_branch(git_dir)
404-
local color
405-
if branch then
406-
-- Has branch => therefore it is a git folder, now figure out status
407-
local gitStatus = get_git_status()
408-
local gitConflict = get_git_conflict()
409-
410-
color = colors.dirty
411-
if gitStatus then
412-
color = colors.clean
413-
end
414-
415-
if gitConflict then
416-
color = colors.conflict
417-
end
418-
419-
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")")
420-
return false
421-
end
422-
end
405+
406+
if git_dir then
407+
-- if we're inside of git repo then try to detect current branch
408+
local branch = get_git_branch(git_dir)
409+
local color = colors.unknown
410+
if branch then
411+
if cmderGitStatusOptIn then
412+
-- Has branch => therefore it is a git folder, now figure out status
413+
local gitStatus = get_git_status()
414+
local gitConflict = get_git_conflict()
415+
416+
color = colors.dirty
417+
if gitStatus then
418+
color = colors.clean
419+
end
420+
421+
if gitConflict then
422+
color = colors.conflict
423+
end
424+
end
425+
426+
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")")
427+
return false
428+
end
423429
end
424430

425431
-- No git present or not in git file

Diff for: vendor/cmder_prompt_config.lua.default

+1
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ lamb_color = "\x1b[1;30;40m" -- Light Grey = Lambda Color
4343
clean_color = "\x1b[1;37;40m"
4444
dirty_color = "\x1b[33;3m"
4545
conflict_color = "\x1b[31;1m"
46+
unknown_color = "\x1b[30;1m"

Diff for: vendor/git-prompt.sh

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ function getGitStatusSetting() {
99
fi
1010
}
1111

12+
function getSimpleGitBranch() {
13+
gitDir=$(git rev-parse --git-dir 2>/dev/null)
14+
if [ -z "$gitDir" ]; then
15+
return 0
16+
fi
17+
18+
headContent=$(< "$gitDir/HEAD")
19+
if [[ "$headContent" == "ref: refs/heads/"* ]]
20+
then
21+
echo " (${headContent:16})"
22+
else
23+
echo " (HEAD detached at ${headContent:0:7})"
24+
fi
25+
}
26+
1227
if test -f /etc/profile.d/git-sdk.sh
1328
then
1429
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
@@ -45,6 +60,9 @@ else
4560
. "$COMPLETION_PATH/git-prompt.sh"
4661
PS1="$PS1"'\[\033[36m\]' # change color to cyan
4762
PS1="$PS1"'`__git_ps1`' # bash function
63+
else
64+
PS1="$PS1"'\[\033[30;1m\]' # change color to gray
65+
PS1="$PS1"'`getSimpleGitBranch`'
4866
fi
4967
fi
5068
fi

Diff for: vendor/psmodules/Cmder.ps1

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function checkGit($Path) {
3636

3737
if (getGitStatusSetting -eq $true) {
3838
Write-VcsStatus
39+
} else {
40+
$headContent = Get-Content (Join-Path $Path '.git/HEAD')
41+
if ($headContent -like "ref: refs/heads/*") {
42+
$branchName = $headContent.Substring(16)
43+
} else {
44+
$branchName = "HEAD detached at $($headContent.Substring(0, 7))"
45+
}
46+
Write-Host " [$branchName]" -NoNewline -ForegroundColor DarkGray
3947
}
4048

4149
return

0 commit comments

Comments
 (0)