From c2629348225654af723600e8b7088e8ebe05aaa0 Mon Sep 17 00:00:00 2001 From: Ian Craig Date: Thu, 20 May 2021 17:53:05 -0700 Subject: [PATCH 01/10] Add branchonly option to cmdstatus --- README.md | 9 +++-- vendor/clink.lua | 53 ++++++++++++++++---------- vendor/cmder_prompt_config.lua.default | 1 + 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index b6e18c0..a419f5b 100644 --- a/README.md +++ b/README.md @@ -194,10 +194,11 @@ You can write `*.cmd|*.bat`, `*.ps1`, and `*.sh` scripts and just drop them in t ``` [cmder] - status = false # Opt out of Git status for 'ALL' Cmder supported shells. - cmdstatus = false # Opt out of Git status for 'Cmd.exe' shells. - psstatus = false # Opt out of Git status for 'Powershell.exe and 'Pwsh.exe' shells. - shstatus = false # Opt out of Git status for 'bash.exe' shells. + status = false # Opt out of Git status for 'ALL' Cmder supported shells. + cmdstatus = false # Opt out of Git status for 'Cmd.exe' shells. + cmdstatus = branchonly # Show branch name in 'Cmd.exe' shells, but don't color according to status (faster) + psstatus = false # Opt out of Git status for 'Powershell.exe and 'Pwsh.exe' shells. + shstatus = false # Opt out of Git status for 'bash.exe' shells. ``` ### Aliases diff --git a/vendor/clink.lua b/vendor/clink.lua index 3c4ee42..a05858d 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -41,6 +41,10 @@ local function get_conflict_color() return conflict_color or "\x1b[31;1m" 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 --- @@ -361,27 +365,29 @@ end --- -- Get the status of working dir --- @return {bool} +-- @return {bool|'branchonly'} --- local function get_git_status_setting() - local gitStatusConfig = io.popen("git --no-pager config cmder.status 2>nul") + local gitCmdStatusConfig = io.popen("git --no-pager config cmder.cmdstatus 2>nul") + for line in gitCmdStatusConfig:lines() do + if string.match(line, 'false') then + gitCmdStatusConfig:close() + return false + elseif string.match(line, 'branchonly') then + gitCmdStatusConfig:close() + return 'branchonly' + end + end + gitCmdStatusConfig:close() + local gitStatusConfig = io.popen("git --no-pager config cmder.status 2>nul") for line in gitStatusConfig:lines() do if string.match(line, 'false') then gitStatusConfig:close() return false end end - - local gitCmdStatusConfig = io.popen("git --no-pager config cmder.cmdstatus 2>nul") - for line in gitCmdStatusConfig:lines() do - if string.match(line, 'false') then - gitCmdStatusConfig:close() - return false - end - end gitStatusConfig:close() - gitCmdStatusConfig:close() return true end @@ -392,7 +398,8 @@ local function git_prompt_filter() local colors = { clean = get_clean_color(), dirty = get_dirty_color(), - conflict = get_conflict_color() + conflict = get_conflict_color(), + unknown = get_unknown_color() } local git_dir = get_git_dir() @@ -403,17 +410,21 @@ local function git_prompt_filter() local branch = get_git_branch(git_dir) local color if branch then - -- Has branch => therefore it is a git folder, now figure out status - local gitStatus = get_git_status() - local gitConflict = get_git_conflict() + if cmderGitStatusOptIn ~= 'branchonly' then + -- Has branch => therefore it is a git folder, now figure out status + local gitStatus = get_git_status() + local gitConflict = get_git_conflict() - color = colors.dirty - if gitStatus then - color = colors.clean - end + color = colors.dirty + if gitStatus then + color = colors.clean + end - if gitConflict then - color = colors.conflict + if gitConflict then + color = colors.conflict + end + else + color = colors.unknown end clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") diff --git a/vendor/cmder_prompt_config.lua.default b/vendor/cmder_prompt_config.lua.default index 5e59c14..5b3068d 100644 --- a/vendor/cmder_prompt_config.lua.default +++ b/vendor/cmder_prompt_config.lua.default @@ -43,3 +43,4 @@ lamb_color = "\x1b[1;30;40m" -- Light Grey = Lambda Color clean_color = "\x1b[1;37;40m" dirty_color = "\x1b[33;3m" conflict_color = "\x1b[31;1m" +unknown_color = "\x1b[30;1m" From 9df8f1a92ad9b02b851410e0c6aa42aab144ea35 Mon Sep 17 00:00:00 2001 From: Ian Craig Date: Tue, 25 May 2021 17:53:41 -0700 Subject: [PATCH 02/10] Revert to boolean, keep branch name when status=false --- README.md | 9 ++++----- vendor/clink.lua | 49 ++++++++++++++++++++++-------------------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index a419f5b..b6e18c0 100644 --- a/README.md +++ b/README.md @@ -194,11 +194,10 @@ You can write `*.cmd|*.bat`, `*.ps1`, and `*.sh` scripts and just drop them in t ``` [cmder] - status = false # Opt out of Git status for 'ALL' Cmder supported shells. - cmdstatus = false # Opt out of Git status for 'Cmd.exe' shells. - cmdstatus = branchonly # Show branch name in 'Cmd.exe' shells, but don't color according to status (faster) - psstatus = false # Opt out of Git status for 'Powershell.exe and 'Pwsh.exe' shells. - shstatus = false # Opt out of Git status for 'bash.exe' shells. + status = false # Opt out of Git status for 'ALL' Cmder supported shells. + cmdstatus = false # Opt out of Git status for 'Cmd.exe' shells. + psstatus = false # Opt out of Git status for 'Powershell.exe and 'Pwsh.exe' shells. + shstatus = false # Opt out of Git status for 'bash.exe' shells. ``` ### Aliases diff --git a/vendor/clink.lua b/vendor/clink.lua index a05858d..4f12c6c 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -365,29 +365,27 @@ end --- -- Get the status of working dir --- @return {bool|'branchonly'} +-- @return {bool} --- local function get_git_status_setting() - local gitCmdStatusConfig = io.popen("git --no-pager config cmder.cmdstatus 2>nul") - for line in gitCmdStatusConfig:lines() do - if string.match(line, 'false') then - gitCmdStatusConfig:close() - return false - elseif string.match(line, 'branchonly') then - gitCmdStatusConfig:close() - return 'branchonly' - end - end - gitCmdStatusConfig:close() - local gitStatusConfig = io.popen("git --no-pager config cmder.status 2>nul") + for line in gitStatusConfig:lines() do if string.match(line, 'false') then gitStatusConfig:close() return false end end + + local gitCmdStatusConfig = io.popen("git --no-pager config cmder.cmdstatus 2>nul") + for line in gitCmdStatusConfig:lines() do + if string.match(line, 'false') then + gitCmdStatusConfig:close() + return false + end + end gitStatusConfig:close() + gitCmdStatusConfig:close() return true end @@ -404,13 +402,13 @@ local function git_prompt_filter() local git_dir = get_git_dir() cmderGitStatusOptIn = get_git_status_setting() - if cmderGitStatusOptIn then - if git_dir then - -- if we're inside of git repo then try to detect current branch - local branch = get_git_branch(git_dir) - local color - if branch then - if cmderGitStatusOptIn ~= 'branchonly' then + + if git_dir then + -- if we're inside of git repo then try to detect current branch + local branch = get_git_branch(git_dir) + local color = colors.unknown + if branch then + if cmderGitStatusOptIn then -- Has branch => therefore it is a git folder, now figure out status local gitStatus = get_git_status() local gitConflict = get_git_conflict() @@ -423,14 +421,11 @@ local function git_prompt_filter() if gitConflict then color = colors.conflict end - else - color = colors.unknown - end + end - clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") - return false - end - end + clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") + return false + end end -- No git present or not in git file From a5c98d4fe92800a5f819c3f9393848311d908f88 Mon Sep 17 00:00:00 2001 From: Ian Craig Date: Tue, 25 May 2021 21:03:28 -0700 Subject: [PATCH 03/10] 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 From c9acb13d0b0f8871b2ea6ea8716a820e8eaa2d60 Mon Sep 17 00:00:00 2001 From: dgames Date: Sun, 30 May 2021 07:50:48 -0400 Subject: [PATCH 04/10] Fix cmder no status prompt --- CHANGELOG.md | 2 + vendor/clink.lua | 84 ++++++++++++++++++++------ vendor/cmder_prompt_config.lua.default | 2 +- vendor/sources.json | 4 +- 4 files changed, 70 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc61977..77d2fdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Changes - Update Git for Windows to 2.31.1 +- Update to Clink 1.2.5 +- Do not rely on having a `%cmder_root%\config\cmder_prompt_config.lua` ### Adds diff --git a/vendor/clink.lua b/vendor/clink.lua index 2c26d4c..d69d4e2 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -13,6 +13,38 @@ dofile(clink_lua_file) -- now add our own things... + +local function get_uah_color() + return uah_color or "\x1b[1;33;40m" -- Green = uah = [user]@[hostname] +end + +local function get_cwd_color() + return cwd_color or "\x1b[1;32;40m" -- Yellow cwd = Current Working Directory +end + +local function get_lamb_color() + return lamb_color or "\x1b[1;30;40m" -- Light Grey = Lambda Color +end + + +local function get_clean_color() + return clean_color or "\x1b[1;37;40m" +end + + +local function get_dirty_color() + return dirty_color or "\x1b[33;3m" +end + + +local function get_conflict_color() + return conflict_color or "\x1b[31;1m" +end + +local function get_unknown_color() + return unknown_color or "\x1b[1;37;40m" +end + --- -- Makes a string safe to use as the replacement in string.gsub --- @@ -65,6 +97,22 @@ local function set_prompt_filter() prompt_lambSymbol = "λ" end + if not prompt_type then + prompt_type = "full" + end + + if prompt_useHomeSymbol == nil then + prompt_useHomeSymbol = false + end + + if prompt_useUserAtHost == nil then + prompt_useUserAtHost = false + end + + if prompt_singleLine == nil then + prompt_singleLine = false + end + if prompt_type == 'folder' then cwd = get_folder_name(cwd) end @@ -83,14 +131,13 @@ local function set_prompt_filter() cr = ' ' end - if env ~= nil then - prompt_lambSymbol = "("..env..") "..prompt_lambSymbol - end + if env ~= nil then env = "("..env..") " else env = "" end - prompt = uah_color .. "{uah}" .. cwd_color .. "{cwd}{git}{hg}{svn}" .. lamb_color .. cr .. "{lamb} \x1b[0m" - uah_value = string.gsub(prompt, "{uah}", uah) - new_value = string.gsub(uah_value, "{cwd}", cwd) - clink.prompt.value = string.gsub(new_value, "{lamb}", prompt_lambSymbol) + prompt = get_uah_color() .. "{uah}" .. get_cwd_color() .. "{cwd}{git}{hg}{svn}" .. get_lamb_color() .. cr .. "{lamb} \x1b[0m" + prompt = string.gsub(prompt, "{uah}", uah) + prompt = string.gsub(prompt, "{cwd}", cwd) + prompt = string.gsub(prompt, "{env}", env) + clink.prompt.value = string.gsub(prompt, "{lamb}", prompt_lambSymbol) end local function percent_prompt_filter() @@ -347,19 +394,19 @@ local function git_prompt_filter() -- Colors for git status local colors = { - clean = clean_color, - dirty = dirty_color, - conflict = conflict_color - nostatus = unknown_color + clean = get_clean_color(), + dirty = get_dirty_color(), + conflict = get_conflict_color(), + nostatus = get_unknown_color() } local git_dir = get_git_dir() + local color cmderGitStatusOptIn = get_git_status_setting() if cmderGitStatusOptIn then if git_dir then -- if we're inside of git repo then try to detect current branch local branch = get_git_branch(git_dir) - local color if branch then -- Has branch => therefore it is a git folder, now figure out status local gitStatus = get_git_status() @@ -381,7 +428,6 @@ local function git_prompt_filter() else if git_dir then local branch = get_git_branch(git_dir) - local color if branch then color = colors.nostatus clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") @@ -404,9 +450,9 @@ local function hg_prompt_filter() if hg_dir then -- Colors for mercurial status local colors = { - clean = clean_color, - dirty = dirty_color, - nostatus = nostatus_color + clean = get_clean_color(), + dirty = get_dirty_color(), + nostatus = get_unknown_color() } local pipe = io.popen("hg branch 2>&1") @@ -439,9 +485,9 @@ end local function svn_prompt_filter() -- Colors for svn status local colors = { - clean = clean_color, - dirty = dirty_color, - nostatus = nostatus_color + clean = get_clean_color(), + dirty = get_dirty_color(), + nostatus = get_unknown_color() } if get_svn_dir() then diff --git a/vendor/cmder_prompt_config.lua.default b/vendor/cmder_prompt_config.lua.default index 366dc62..ab3191f 100644 --- a/vendor/cmder_prompt_config.lua.default +++ b/vendor/cmder_prompt_config.lua.default @@ -43,4 +43,4 @@ lamb_color = "\x1b[1;30;40m" -- Light Grey = Lambda Color clean_color = "\x1b[1;37;40m" dirty_color = "\x1b[33;3m" conflict_color = "\x1b[31;1m" -unknown_color = "\x1b[1;30;40m" -- Light Grey = No VCS Status Branch Color +unknown_color = "\x1b[1;37;40m" -- White = No VCS Status Branch Color diff --git a/vendor/sources.json b/vendor/sources.json index b552653..f2423a4 100644 --- a/vendor/sources.json +++ b/vendor/sources.json @@ -6,8 +6,8 @@ }, { "name": "clink", - "version": "1.1.45", - "url": "https://github.com/chrisant996/clink/releases/download/v1.1.45/clink.1.1.45.1c3985.zip" + "version": "1.2.5", + "url": "https://github.com/chrisant996/clink/releases/download/v1.2.5/clink.1.2.5.5dd017.zip" }, { "name": "conemu-maximus5", From 4fab4cc6e4fba06f4a8cf13a74afcf2e112fd6e1 Mon Sep 17 00:00:00 2001 From: dgames Date: Sun, 30 May 2021 08:41:40 -0400 Subject: [PATCH 05/10] make unknown color white for all shells --- vendor/git-prompt.sh | 2 +- vendor/psmodules/Cmder.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/git-prompt.sh b/vendor/git-prompt.sh index ccda575..957dcdc 100644 --- a/vendor/git-prompt.sh +++ b/vendor/git-prompt.sh @@ -61,7 +61,7 @@ else 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"'\[\033[37;1m\]' # change color to white PS1="$PS1"'`getSimpleGitBranch`' fi fi diff --git a/vendor/psmodules/Cmder.ps1 b/vendor/psmodules/Cmder.ps1 index 5ede0cf..755d4a7 100644 --- a/vendor/psmodules/Cmder.ps1 +++ b/vendor/psmodules/Cmder.ps1 @@ -43,7 +43,7 @@ function checkGit($Path) { } else { $branchName = "HEAD detached at $($headContent.Substring(0, 7))" } - Write-Host " [$branchName]" -NoNewline -ForegroundColor DarkGray + Write-Host " [$branchName]" -NoNewline -ForegroundColor White } return From 73ad62eaa2c08c9e7ae0192e9139676566523a34 Mon Sep 17 00:00:00 2001 From: dgames Date: Sun, 30 May 2021 08:46:08 -0400 Subject: [PATCH 06/10] add xxx --- xxx | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 xxx diff --git a/xxx b/xxx new file mode 100644 index 0000000..e69de29 From 413fb2f1ac9ad18785cae2b745bc4919dfe7a678 Mon Sep 17 00:00:00 2001 From: dgames Date: Sun, 30 May 2021 08:46:37 -0400 Subject: [PATCH 07/10] remove xxx --- xxx | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 xxx diff --git a/xxx b/xxx deleted file mode 100644 index e69de29..0000000 From aebe37bd282afb361dff54601a056168deab0278 Mon Sep 17 00:00:00 2001 From: dgames Date: Sun, 30 May 2021 08:56:05 -0400 Subject: [PATCH 08/10] fix default unknown color --- vendor/clink.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/clink.lua b/vendor/clink.lua index 5bf3612..89550c4 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -42,7 +42,7 @@ local function get_conflict_color() end local function get_unknown_color() - return unknown_color or "\x1b[1;37;40m" + return unknown_color or "\x1b[37;1m" end --- From 55ff6110952dde45ee561f1e30d4c2778cb019b0 Mon Sep 17 00:00:00 2001 From: dgames Date: Sun, 30 May 2021 08:56:44 -0400 Subject: [PATCH 09/10] fix default unknown color --- vendor/cmder_prompt_config.lua.default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/cmder_prompt_config.lua.default b/vendor/cmder_prompt_config.lua.default index ab3191f..a33de81 100644 --- a/vendor/cmder_prompt_config.lua.default +++ b/vendor/cmder_prompt_config.lua.default @@ -43,4 +43,4 @@ lamb_color = "\x1b[1;30;40m" -- Light Grey = Lambda Color clean_color = "\x1b[1;37;40m" dirty_color = "\x1b[33;3m" conflict_color = "\x1b[31;1m" -unknown_color = "\x1b[1;37;40m" -- White = No VCS Status Branch Color +unknown_color = "\x1b[37;1" -- White = No VCS Status Branch Color From 56b04fc9ce252c4c1e45023db81c17e667377aba Mon Sep 17 00:00:00 2001 From: dgames Date: Mon, 31 May 2021 10:53:18 -0400 Subject: [PATCH 10/10] fix unknown color and code dedup --- vendor/clink.lua | 50 +++++++++++--------------- vendor/cmder_prompt_config.lua.default | 2 +- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/vendor/clink.lua b/vendor/clink.lua index 89550c4..2110548 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -403,37 +403,29 @@ local function git_prompt_filter() local git_dir = get_git_dir() local color cmderGitStatusOptIn = get_git_status_setting() - if cmderGitStatusOptIn then - if git_dir then - -- if we're inside of git repo then try to detect current branch - local branch = get_git_branch(git_dir) - if branch then - -- Has branch => therefore it is a git folder, now figure out status - local gitStatus = get_git_status() - local gitConflict = get_git_conflict() + if git_dir then + local branch = get_git_branch(git_dir) + if branch then + if cmderGitStatusOptIn then + -- if we're inside of git repo then try to detect current branch + -- Has branch => therefore it is a git folder, now figure out status + local gitStatus = get_git_status() + local gitConflict = get_git_conflict() - color = colors.dirty - if gitStatus then - color = colors.clean - end + color = colors.dirty + if gitStatus then + color = colors.clean + end - if gitConflict then - color = colors.conflict - end - - clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") - return false - end - end - else - if git_dir then - local branch = get_git_branch(git_dir) - if branch then - color = colors.nostatus - clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") - return false - end - end + if gitConflict then + color = colors.conflict + end + else + color = colors.nostatus + end + clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")") + return false + end end -- No git present or not in git file diff --git a/vendor/cmder_prompt_config.lua.default b/vendor/cmder_prompt_config.lua.default index a33de81..e5ae224 100644 --- a/vendor/cmder_prompt_config.lua.default +++ b/vendor/cmder_prompt_config.lua.default @@ -43,4 +43,4 @@ lamb_color = "\x1b[1;30;40m" -- Light Grey = Lambda Color clean_color = "\x1b[1;37;40m" dirty_color = "\x1b[33;3m" conflict_color = "\x1b[31;1m" -unknown_color = "\x1b[37;1" -- White = No VCS Status Branch Color +unknown_color = "\x1b[37;1m" -- White = No VCS Status Branch Color