From 8a885167c3d5cab6833e30ffb2c6abd80af582fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bo=C5=82dys?= Date: Mon, 23 Feb 2015 13:23:39 +0100 Subject: [PATCH] mercurial prompt --- config/git.lua | 3 ++- config/hg.lua | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ vendor/init.bat | 2 +- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 config/hg.lua diff --git a/config/git.lua b/config/git.lua index 94b953672..7f12b0a41 100644 --- a/config/git.lua +++ b/config/git.lua @@ -39,6 +39,7 @@ function git_prompt_filter() end clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..branch..")") + clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", "") return true end @@ -47,4 +48,4 @@ function git_prompt_filter() return false end -clink.prompt.register_filter(git_prompt_filter, 50) \ No newline at end of file +clink.prompt.register_filter(git_prompt_filter, 50) diff --git a/config/hg.lua b/config/hg.lua new file mode 100644 index 000000000..b630ba7f0 --- /dev/null +++ b/config/hg.lua @@ -0,0 +1,54 @@ +--- + -- Find out current branch + -- @return {false|mercurial branch name} +--- +function get_hg_branch() + for line in io.popen("hg branch 2>nul"):lines() do + local m = line:match("(.+)$") + if m then + return m + end + end + + return false +end + +--- + -- Get the status of working dir + -- @return {bool} +--- +function get_hg_status() + for line in io.popen("hg status"):lines() do + return false + end + return true +end + +function hg_prompt_filter() + + -- Colors for mercurial status + local colors = { + clean = "\x1b[1;37;40m", + dirty = "\x1b[31;1m", + } + + local branch = get_hg_branch() + if branch then + -- Has branch => therefore it is a mercurial folder, now figure out status + if get_hg_status() then + color = colors.clean + else + color = colors.dirty + end + + clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", color.."("..branch..")") + clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "") + return true + end + + -- No mercurial present or not in mercurial file + clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", "") + return false +end + +clink.prompt.register_filter(hg_prompt_filter, 50) diff --git a/vendor/init.bat b/vendor/init.bat index 7734f47a4..bf36eac06 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -9,7 +9,7 @@ :: Change the prompt style :: Mmm tasty lamb -@prompt $E[1;32;40m$P$S{git}$S$_$E[1;30;40m{lamb}$S$E[0m +@prompt $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m :: Pick right version of clink @if "%PROCESSOR_ARCHITECTURE%"=="x86" (