diff options
| author | Senghan Bright <senghan.bright@deltaprojects.com> | 2021-04-09 19:33:10 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-09 13:33:10 -0400 |
| commit | 5bd6f5ca9828ea02f2c54d616ad65c72a5cdd7fb (patch) | |
| tree | 4308ec84d1dfb040cf9297117133251966e3deae /lua | |
| parent | ba1e674e68a251ce7dcaf44a7b815431ba563f8f (diff) | |
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>
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/telescope/make_entry.lua | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index c714e7b..b9635bb 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -1019,28 +1019,51 @@ function make_entry.gen_from_autocommands(_) end end +local git_icon_defaults = { + added = "+", + changed = "~", + copied = ">", + deleted = "-", + renamed = "➡", + unmerged = "‡", + untracked = "?" +} + function make_entry.gen_from_git_status(opts) + opts = opts or {} + + local col_width = ((opts.git_icons and opts.git_icons.added) and opts.git_icons.added:len() + 2) or 2 local displayer = entry_display.create { - separator = " ", + separator = "", items = { - { width = 1 }, - { width = 1 }, + { width = col_width}, + { width = col_width}, { remaining = true }, } } - local make_display = function(entry) - local modified = "TelescopeResultsDiffChange" - local staged = "TelescopeResultsDiffAdd" + local icons = vim.tbl_extend("keep", opts.git_icons or {}, git_icon_defaults) - if entry.status == "??" then - modified = "TelescopeResultsDiffDelete" - staged = "TelescopeResultsDiffDelete" - end + local git_abbrev = { + ["A"] = {icon = icons.added, hl = "TelescopeResultsDiffAdd"}, + ["U"] = {icon = icons.unmerged, hl = "TelescopeResultsDiffAdd"}, + ["M"] = {icon = icons.changed, hl = "TelescopeResultsDiffChange"}, + ["C"] = {icon = icons.copied, hl = "TelescopeResultsDiffChange"}, + ["R"] = {icon = icons.renamed, hl = "TelescopeResultsDiffChange"}, + ["D"] = {icon = icons.deleted, hl = "TelescopeResultsDiffDelete"}, + ["?"] = {icon = icons.untracked, hl = "TelescopeResultsDiffUntracked"}, + } + + local make_display = function(entry) + local x = string.sub(entry.status, 1, 1) + local y = string.sub(entry.status, -1) + local status_x = git_abbrev[x] or {} + local status_y = git_abbrev[y] or {} + local empty_space = (" ") return displayer { - { string.sub(entry.status, 1, 1), staged }, - { string.sub(entry.status, -1), modified }, + { status_x.icon or empty_space, status_x.hl}, + { status_y.icon or empty_space, status_y.hl}, entry.value, } end |
