diff --git a/lua/telescope/builtin/git.lua b/lua/telescope/builtin/git.lua index df88c4d..309f6e2 100644 --- a/lua/telescope/builtin/git.lua +++ b/lua/telescope/builtin/git.lua @@ -117,16 +117,7 @@ git.status = function(opts) prompt_title = 'Git Status', finder = finders.new_table { results = vim.split(output, '\n'), - entry_maker = function(entry) - if entry == '' then return nil end - local mod, file = string.match(entry, '(..).*%s[->%s]?(.+)') - return { - value = file, - status = mod, - ordinal = entry, - display = entry, - } - end + entry_maker = make_entry.gen_from_git_status(opts) }, previewer = previewers.git_file_diff.new(opts), sorter = conf.file_sorter(opts), diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 7456e2b..17a5e4c 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -899,4 +899,43 @@ function make_entry.gen_from_autocommands(_) end end +function make_entry.gen_from_git_status(_) + local displayer = entry_display.create { + separator = " ", + items = { + { width = 1}, + { width = 1}, + { remaining = true }, + } + } + + local make_display = function(entry) + local modified = "TelescopeResultsDiffChange" + local staged = "TelescopeResultsDiffAdd" + + if entry.status == "??" then + modified = "TelescopeResultsDiffDelete" + staged = "TelescopeResultsDiffDelete" + end + + return displayer { + { string.sub(entry.status, 1, 1), staged}, + { string.sub(entry.status, -1), modified}, + entry.value, + } + end + + return function (entry) + if entry == '' then return nil end + local mod, file = string.match(entry, '(..).*%s[->%s]?(.+)') + return { + value = file, + status = mod, + ordinal = entry, + display = make_display, + } + end +end + + return make_entry diff --git a/plugin/telescope.vim b/plugin/telescope.vim index a24bd06..697457b 100644 --- a/plugin/telescope.vim +++ b/plugin/telescope.vim @@ -40,6 +40,11 @@ highlight default link TelescopeResultsNumber Number highlight default link TelescopeResultsComment Comment highlight default link TelescopeResultsSpecialComment SpecialComment +" Used for git status Results highlighting +highlight default link TelescopeResultsDiffChange DiffChange +highlight default link TelescopeResultsDiffAdd DiffAdd +highlight default link TelescopeResultsDiffDelete DiffDelete + " This is like "" in your terminal. " To use it, do `cmap (TelescopeFuzzyCommandSearch) cnoremap (TelescopeFuzzyCommandSearch) e