Last active
July 26, 2026 09:46
-
-
Save richardgill/050a30e1c253dd8a20413f614b563ed0 to your computer and use it in GitHub Desktop.
CodeDiff Explorer formatters using mini.icons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local MiniIcons = require("mini.icons") | |
| MiniIcons.setup() | |
| local group_labels = { | |
| staged = "INDEX", | |
| unstaged = "WORKTREE", | |
| conflicts = "CONFLICT", | |
| } | |
| local file_count = function(count) | |
| return count .. (count == 1 and " file" or " files") | |
| end | |
| local mini_prefix = function(ctx, category) | |
| local icon, icon_hl = MiniIcons.get(category, ctx.path) | |
| local segments = { | |
| { text = ctx.indent, hl = ctx.indent_hl }, | |
| } | |
| if category == "directory" then | |
| segments[#segments + 1] = { | |
| text = ctx.expanded and " " or " ", | |
| hl = "Comment", | |
| } | |
| end | |
| segments[#segments + 1] = { | |
| text = icon .. " ", | |
| hl = icon_hl, | |
| } | |
| return segments | |
| end | |
| return { | |
| file = function(ctx) | |
| return { | |
| left = { | |
| { segments = mini_prefix(ctx, "file") }, | |
| { | |
| segments = { { text = ctx.filename, hl = "Normal" } }, | |
| truncate_priority = 1, | |
| }, | |
| }, | |
| right = { | |
| { | |
| segments = { | |
| { | |
| text = ("%s · %s"):format(group_labels[ctx.group], ctx.status), | |
| hl = ctx.status_hl, | |
| }, | |
| { text = " ", hl = "Normal" }, | |
| }, | |
| }, | |
| }, | |
| } | |
| end, | |
| folder = function(ctx) | |
| return { | |
| left = { | |
| { segments = mini_prefix(ctx, "directory") }, | |
| { | |
| segments = { | |
| { | |
| text = ctx.name, | |
| hl = { fg = "#f9e2af", bold = true }, | |
| }, | |
| }, | |
| truncate_priority = 1, | |
| }, | |
| }, | |
| right = { | |
| { | |
| segments = { | |
| { text = file_count(ctx.file_count), hl = "Comment" }, | |
| { text = " ", hl = "Normal" }, | |
| }, | |
| }, | |
| }, | |
| } | |
| end, | |
| group = function(ctx) | |
| return { | |
| left = { | |
| { | |
| segments = { | |
| { | |
| text = " ◆ " .. ctx.label, | |
| hl = { fg = "#cba6f7", bold = true }, | |
| }, | |
| }, | |
| truncate_priority = 1, | |
| }, | |
| }, | |
| right = { | |
| { | |
| segments = { | |
| { | |
| text = file_count(ctx.file_count), | |
| hl = { fg = "#89b4fa", bold = true }, | |
| }, | |
| { text = " ", hl = "Normal" }, | |
| }, | |
| }, | |
| }, | |
| } | |
| end, | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment