summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric M'Passi <cempassi@student.42.fr>2021-01-04 23:04:58 +0100
committerGitHub <noreply@github.com>2021-01-04 23:04:58 +0100
commit9503603f888305ec799c9346f51a6e3da7f5b89b (patch)
tree2831b855a769249c0befcb390d49b243f87e5fc3
parent313ce9d0b6fb3bdb5ee07af60ee8840bdd4fbf73 (diff)
feat: Add highlight to builtin.git_status (#388)
-rw-r--r--lua/telescope/builtin/git.lua11
-rw-r--r--lua/telescope/make_entry.lua39
-rw-r--r--plugin/telescope.vim5
3 files changed, 45 insertions, 10 deletions
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 "<C-R>" in your terminal.
" To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch)
cnoremap <silent> <Plug>(TelescopeFuzzyCommandSearch) <C-\>e