From c2b37021d4cf039515eb0bf0648b09c1d39dd184 Mon Sep 17 00:00:00 2001 From: Samuel Vasko Date: Fri, 15 Nov 2013 17:06:15 +0100 Subject: [PATCH] Now with git in prompt (fix for #13) --- config/git.lua | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ vendor/init.bat | 5 +++-- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 config/git.lua diff --git a/config/git.lua b/config/git.lua new file mode 100644 index 0000000..7939875 --- /dev/null +++ b/config/git.lua @@ -0,0 +1,50 @@ +--- + -- Find out current branch + -- @return {false|git branch name} +--- +function get_git_branch() + for line in io.popen("git 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_git_status() + return os.execute("git diff-files --quiet --ignore-submodules") +end + +function git_prompt_filter() + + -- Colors for git status + local colors = { + clean = "\x1b[1;37;40m", + dirty = "\x1b[31;1m", + } + + local branch = get_git_branch() + if branch then + -- Has branch => therefore it is a git folder, now figure out status + if get_git_status() then + color = colors.clean + else + color = colors.dirty + end + + clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..branch..")") + return true + end + + -- No git present or not in git file + clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "") + return false +end + +clink.prompt.register_filter(git_prompt_filter, 50) \ No newline at end of file diff --git a/vendor/init.bat b/vendor/init.bat index 6f3a7d7..bf7a5bc 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -9,7 +9,7 @@ :: World without Unicode is a sad world @chcp 65001>nul :: It has to be lambda, I already made a logo -@prompt $E[1;32;40m$P $_$E[1;30;40mλ $E[0m +@prompt $E[1;32;40m$P$S{git}$S$_$E[1;30;40mλ$S$E[0m @chcp %cp%>nul @@ -38,9 +38,10 @@ :: Add aliases @doskey /macrofile=%rootDir%\config\aliases -:: Set home path :: cd into users homedir @cd /d %USERPROFILE% + +:: Set home path @set HOME=%USERPROFILE% @echo Welcome to cmder! \ No newline at end of file