From b75b3239e7b9d74a83f7eafa9d34fb6a3a63bbbb Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Thu, 19 Mar 2015 23:53:29 +0300 Subject: [PATCH] Adds clink-completions as an external dependency * Adds package to sources.json * Merges all cmder's lua modules into one -> cmder.lua to exclude future conflicts * Adds external modules loading logic --- config/cmder.lua | 121 ++++++++++++++++++++++++++++++++++++++++++++ config/git.lua | 51 ------------------- config/hg.lua | 54 -------------------- config/prompt.lua | 5 -- vendor/sources.json | 5 ++ 5 files changed, 126 insertions(+), 110 deletions(-) create mode 100644 config/cmder.lua delete mode 100644 config/git.lua delete mode 100644 config/hg.lua delete mode 100644 config/prompt.lua diff --git a/config/cmder.lua b/config/cmder.lua new file mode 100644 index 0000000..5c5de11 --- /dev/null +++ b/config/cmder.lua @@ -0,0 +1,121 @@ +function lambda_prompt_filter() + clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "λ") +end + +--- + -- 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 + +--- + -- 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 --quiet --ignore-submodules HEAD") +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..")") + clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", "") + 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(lambda_prompt_filter, 40) +clink.prompt.register_filter(hg_prompt_filter, 50) +clink.prompt.register_filter(git_prompt_filter, 50) + +local completions_dir = clink.get_env('CMDER_ROOT')..'/vendor/clink-completions/' +for _,lua_module in ipairs(clink.find_files(completions_dir..'*.lua')) do + -- Skip files that starts with _. This could be useful if some files should be ignored + if not string.match(lua_module, '^_.*') then + local filename = completions_dir..lua_module + -- use dofile instead of require because require caches loaded modules + -- so config reloading using Alt-Q won't reload updated modules. + dofile(filename) + end +end \ No newline at end of file diff --git a/config/git.lua b/config/git.lua deleted file mode 100644 index 7f12b0a..0000000 --- a/config/git.lua +++ /dev/null @@ -1,51 +0,0 @@ ---- - -- 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 --quiet --ignore-submodules HEAD") -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..")") - clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", "") - 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) diff --git a/config/hg.lua b/config/hg.lua deleted file mode 100644 index b630ba7..0000000 --- a/config/hg.lua +++ /dev/null @@ -1,54 +0,0 @@ ---- - -- 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/config/prompt.lua b/config/prompt.lua deleted file mode 100644 index 5b0c239..0000000 --- a/config/prompt.lua +++ /dev/null @@ -1,5 +0,0 @@ -function lambda_prompt_filter() - clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "λ") -end - -clink.prompt.register_filter(lambda_prompt_filter, 40) \ No newline at end of file diff --git a/vendor/sources.json b/vendor/sources.json index c508f5e..362e2b4 100644 --- a/vendor/sources.json +++ b/vendor/sources.json @@ -13,5 +13,10 @@ "name": "conemu-maximus5", "version": "150215", "url": "https://conemu.codeplex.com/downloads/get/1430634" + }, + { + "name": "clink-completions", + "version": "0.1.0", + "url": "https://github.com/vladimir-kotikov/clink-completions/archive/0.1.0.zip" } ]