Skip to content

Commit 5bd6f5c

Browse files
sunjontjdevries
andauthored
feat: add icons to git_status finder (#401)
* add icons to git_status finder * fix lint warning * fix incorrect removed icon * refactor, more states/icons * refactor, widen columns to allow for 3char width icons * attempted col width fix * fixup: small comments Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
1 parent ba1e674 commit 5bd6f5c

3 files changed

Lines changed: 36 additions & 48 deletions

File tree

lua/telescope/make_entry.lua

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,28 +1019,51 @@ function make_entry.gen_from_autocommands(_)
10191019
end
10201020
end
10211021

1022+
local git_icon_defaults = {
1023+
added = "+",
1024+
changed = "~",
1025+
copied = ">",
1026+
deleted = "-",
1027+
renamed = "",
1028+
unmerged = "",
1029+
untracked = "?"
1030+
}
1031+
10221032
function make_entry.gen_from_git_status(opts)
1033+
opts = opts or {}
1034+
1035+
local col_width = ((opts.git_icons and opts.git_icons.added) and opts.git_icons.added:len() + 2) or 2
10231036
local displayer = entry_display.create {
1024-
separator = " ",
1037+
separator = "",
10251038
items = {
1026-
{ width = 1 },
1027-
{ width = 1 },
1039+
{ width = col_width},
1040+
{ width = col_width},
10281041
{ remaining = true },
10291042
}
10301043
}
10311044

1032-
local make_display = function(entry)
1033-
local modified = "TelescopeResultsDiffChange"
1034-
local staged = "TelescopeResultsDiffAdd"
1045+
local icons = vim.tbl_extend("keep", opts.git_icons or {}, git_icon_defaults)
10351046

1036-
if entry.status == "??" then
1037-
modified = "TelescopeResultsDiffDelete"
1038-
staged = "TelescopeResultsDiffDelete"
1039-
end
1047+
local git_abbrev = {
1048+
["A"] = {icon = icons.added, hl = "TelescopeResultsDiffAdd"},
1049+
["U"] = {icon = icons.unmerged, hl = "TelescopeResultsDiffAdd"},
1050+
["M"] = {icon = icons.changed, hl = "TelescopeResultsDiffChange"},
1051+
["C"] = {icon = icons.copied, hl = "TelescopeResultsDiffChange"},
1052+
["R"] = {icon = icons.renamed, hl = "TelescopeResultsDiffChange"},
1053+
["D"] = {icon = icons.deleted, hl = "TelescopeResultsDiffDelete"},
1054+
["?"] = {icon = icons.untracked, hl = "TelescopeResultsDiffUntracked"},
1055+
}
1056+
1057+
local make_display = function(entry)
1058+
local x = string.sub(entry.status, 1, 1)
1059+
local y = string.sub(entry.status, -1)
1060+
local status_x = git_abbrev[x] or {}
1061+
local status_y = git_abbrev[y] or {}
10401062

1063+
local empty_space = (" ")
10411064
return displayer {
1042-
{ string.sub(entry.status, 1, 1), staged },
1043-
{ string.sub(entry.status, -1), modified },
1065+
{ status_x.icon or empty_space, status_x.hl},
1066+
{ status_y.icon or empty_space, status_y.hl},
10441067
entry.value,
10451068
}
10461069
end

plugin/telescope.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ highlight default link TelescopeResultsSpecialComment SpecialComment
6969
highlight default link TelescopeResultsDiffChange DiffChange
7070
highlight default link TelescopeResultsDiffAdd DiffAdd
7171
highlight default link TelescopeResultsDiffDelete DiffDelete
72+
highlight default link TelescopeResultsDiffUntracked NonText
7273

7374
" This is like "<C-R>" in your terminal.
7475
" To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch)

scratch/old_perf_debug

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)