Skip to content

Commit

Permalink
show count of modified/normal buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
davidosomething committed May 10, 2023
1 parent 3eec7b0 commit 349dbe1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
31 changes: 31 additions & 0 deletions nvim/lua/dko/heirline/bufferstats.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
return {
init = function(self)
self.all = vim.api.nvim_list_bufs()

self.normal = vim.tbl_filter(function(bufnr)
return not require("dko.utils.buffer").is_special(bufnr)
end, self.all)

self.modified = vim.tbl_filter(function(bufnr)
return vim.api.nvim_buf_get_option(bufnr, "modified")
end, self.normal)
end,
{
provider = "",
hl = "StatusLineNC",
},
{
provider = function(self)
return ("%d"):format(#self.modified)
end,
hl = function(self)
return #self.modified > 0 and "TODO" or "StatusLineNC"
end,
},
{
provider = function(self)
return ("/%d"):format(#self.normal)
end,
hl = "StatusLineNC",
},
}
1 change: 1 addition & 0 deletions nvim/lua/dko/heirline/tabline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ return {

require("dko.heirline.cwd"),
require("dko.heirline.git"),
require("dko.heirline.bufferstats"),

{ provider = "%=", hl = "StatusLineNC" },

Expand Down
23 changes: 23 additions & 0 deletions nvim/lua/dko/utils/buffers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
-- Operations on multiple buffers
---

local M = {}

---@param bufnrs table like vim.api.nvim_list_bufs()
---@return table only modified
M.filter_modified = function(bufnrs)
return vim.tbl_filter(function(bufnr)
return vim.api.nvim_buf_get_option(bufnr, "modified")
end, bufnrs)
end

---@param bufnrs table like vim.api.nvim_list_bufs()
---@return table only special
M.filter_special = function(bufnrs)
return vim.tbl_filter(function(bufnr)
return require('dko.utils.buffer').is_special(bufnr)
end, bufnrs)
end

return M
7 changes: 4 additions & 3 deletions nvim/lua/dko/utils/string.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ end
-- alt F ғ (ghayn)
-- alt Q ꞯ (currently using ogonek)
local smallcaps =
"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀsᴛᴜᴠᴡxʏᴢ‹›"
local letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ<>"
"ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀsᴛᴜᴠᴡxʏᴢ‹›⁰¹²³⁴⁵⁶⁷⁸⁹"
local normal = "ABCDEFGHIJKLMNOPQRSTUVWXYZ<>0123456789"

---@param text string
M.smallcaps = function(text)
return vim.fn.tr(text:upper(), letters, smallcaps)
return vim.fn.tr(text:upper(), normal, smallcaps)
end

return M

0 comments on commit 349dbe1

Please sign in to comment.