From 5a48e568a80a1977ffb0ffbda98c2393a7b7fb4c Mon Sep 17 00:00:00 2001 From: b0bh00d Date: Tue, 1 Jan 2019 11:17:53 -0700 Subject: [PATCH 1/2] Updated the HG prompt code to use the '-ib' option to 'hg id' to always have the branch name available. --- vendor/clink.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/vendor/clink.lua b/vendor/clink.lua index 2530510..a949b55 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -324,15 +324,19 @@ local function hg_prompt_filter() dirty = "\x1b[31;1m", } - -- 'hg id' gives us BOTH the branch name AND an indicator that there - -- are uncommitted changes, in one fast(er) call - local pipe = io.popen("hg id 2>&1") + -- 'hg id -ib' gives us BOTH the branch name AND an indicator that there + -- are uncommitted changes, in one fast(er) call compared to "hg status" + local pipe = io.popen("hg id -ib 2>&1") local output = pipe:read('*all') local rc = { pipe:close() } + -- strip the trailing newline from the branch name + local n = #output + while n > 0 and output:find("^%s", n) do n = n - 1 end + output = output:sub(1, n) + if output ~= nil and string.sub(output,1,7) ~= "abort: " and -- not an HG working copy - string.sub(output,1,12) ~= "000000000000" and -- empty wc (needs update) (not string.find(output, "is not recognized")) then -- 'hg' not in path local color = colors.clean -- split elements on space delimiter @@ -342,8 +346,12 @@ local function hg_prompt_filter() end -- if the repo hash ends with '+', the wc has uncommitted changes if string.sub(items[1], -1, -1) == "+" then color = colors.dirty end - -- substitute the branch in directly -- already WITH parentheses. :) - result = color .. items[2] -- string.sub(items[2], 1, string.len(items[2]) - 1) + -- substitute the branch in directly + if items[2] ~= nil then + result = color .. "(" .. items[2] .. ")" + else + result = color .. "*" + end end end From 89499f2a6068980256ca1132714407fdbcdc282a Mon Sep 17 00:00:00 2001 From: b0bh00d Date: Sun, 20 Jan 2019 21:02:31 -0700 Subject: [PATCH 2/2] Replaced the 'hg -id' command with the 'hg branch' and 'hg status' pair for improved response times. --- vendor/clink.lua | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/vendor/clink.lua b/vendor/clink.lua index a949b55..d5f6876 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -324,34 +324,26 @@ local function hg_prompt_filter() dirty = "\x1b[31;1m", } - -- 'hg id -ib' gives us BOTH the branch name AND an indicator that there - -- are uncommitted changes, in one fast(er) call compared to "hg status" - local pipe = io.popen("hg id -ib 2>&1") + local pipe = io.popen("hg branch 2>&1") local output = pipe:read('*all') local rc = { pipe:close() } -- strip the trailing newline from the branch name local n = #output while n > 0 and output:find("^%s", n) do n = n - 1 end - output = output:sub(1, n) + local branch = output:sub(1, n) - if output ~= nil and - string.sub(output,1,7) ~= "abort: " and -- not an HG working copy - (not string.find(output, "is not recognized")) then -- 'hg' not in path + if branch ~= nil and + string.sub(branch,1,7) ~= "abort: " and -- not an HG working copy + (not string.find(branch, "is not recognized")) then -- 'hg' not in path local color = colors.clean - -- split elements on space delimiter - local items = {} - for i in string.gmatch(output, "%S+") do - table.insert(items, i) - end - -- if the repo hash ends with '+', the wc has uncommitted changes - if string.sub(items[1], -1, -1) == "+" then color = colors.dirty end - -- substitute the branch in directly - if items[2] ~= nil then - result = color .. "(" .. items[2] .. ")" - else - result = color .. "*" - end + + local pipe = io.popen("hg status -amrd 2>&1") + local output = pipe:read('*all') + local rc = { pipe:close() } + + if output ~= nil and output ~= "" then color = colors.dirty end + result = color .. "(" .. branch .. ")" end end