summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortriethyl <triethylammonium@pm.me>2026-03-29 17:23:15 -0400
committertriethyl <triethylammonium@pm.me>2026-03-29 17:23:15 -0400
commit7f42af47d2169f8cdaaffc36e8e4e17d44ddfacf (patch)
treec962e2f43cff032d4ff62c375768afd63abe319d
parent716798a809d70ef31b2738544b34b793b7cc5c00 (diff)
added filename component, fixed shortening, and various other fixesmain
-rw-r--r--lua/lineage.lua99
1 files changed, 72 insertions, 27 deletions
diff --git a/lua/lineage.lua b/lua/lineage.lua
index 6386610..4f06798 100644
--- a/lua/lineage.lua
+++ b/lua/lineage.lua
@@ -6,7 +6,6 @@ M.hi_pattern = hi_pattern
-- Use icons?
M.use_icons = false
-local use_icons = M.use_icons
-- Utilities
local utils = {}
@@ -114,6 +113,43 @@ M.components.location = function (args)
return before.."%(%l/%L%): %c"..after
end
+M.components.filename = function (args)
+ args = args or {}
+ local before = args.before or ""
+ local after = args.after or ""
+ local shorten_percentage = args.shorten_percentage or 70
+
+ -- Get filename
+ local filename = vim.fn.expand("%t")
+
+ -- Shorten if too large
+ if utils.component_takes_percentage(#filename, shorten_percentage) then
+ filename = vim.fn.pathshorten(filename)
+ end
+
+ -- Handle empty filenames
+ if filename == "" then
+ filename = "[No Name]"
+ end
+
+ -- Get modified status
+ local modified_bool = vim.bo.modified
+ local modifiable_bool = vim.bo.modifiable
+
+ local modified = ""
+
+ if modified_bool then modified = "[+]" end
+ if not modifiable_bool then modified = "[-]" end
+
+ -- append space if not empty
+ if modified ~= "" then
+ modified = " "..modified
+ end
+
+ -- Compose component
+ return before..filename..modified..after
+end
+
M.components.progress = function (args)
args = args or {}
local before = args.before or ""
@@ -125,8 +161,8 @@ M.components.progress = function (args)
local sbar = { '🭶', '🭷', '🭸', '🭹', '🭺', '🭻' }
local curr_line = vim.api.nvim_win_get_cursor(0)[1] or 0
local lines = vim.api.nvim_buf_line_count(0) or 0
+ if lines == 0 then return "" end -- prevent division by zero
local i = math.floor((curr_line - 1) / lines * #sbar) + 1
- if i == nil then return "" end
local prog = string.rep(sbar[i], 2)
return before..hi_pattern:format("Visual", prog)..after
end
@@ -135,11 +171,14 @@ M.components.cwd = function (args)
args = args or {}
local before = args.before or ""
local after = args.after or ""
+ local shorten_percentage = args.shorten_percentage or 30
local cwd = vim.fn.getcwd(0)
cwd = vim.fn.fnamemodify(cwd, ":~")
- if utils.component_takes_percentage(#cwd, 40) then cwd = vim.fn.pathshorten(cwd) end
- if utils.component_takes_percentage(#cwd, 80) then return "" end
+ if utils.component_takes_percentage(#cwd, shorten_percentage) then
+ cwd = vim.fn.pathshorten(cwd)
+ end
+
local trail = cwd:sub(-1) == '/' and '' or "/"
return before..cwd..trail..after
end
@@ -150,10 +189,10 @@ M.components.diagnostics = function (args)
local after = args.after or ""
-- Define icons
- local error_icon = use_icons and " " or "E"
- local warning_icon = use_icons and " " or "W"
- local info_icon = use_icons and " " or "I"
- local hint_icon = use_icons and " " or "H"
+ local error_icon = M.use_icons and " " or "E"
+ local warning_icon = M.use_icons and " " or "W"
+ local info_icon = M.use_icons and " " or "I"
+ local hint_icon = M.use_icons and " " or "H"
-- Create empty diagnostics table
local diagnostics = {}
@@ -188,7 +227,7 @@ M.components.diagnostics = function (args)
return ""
end
- local icon = use_icons and '' or 'diag: '
+ local icon = M.use_icons and '' or 'diag: '
local status = hi_pattern:format("Statusline", table.concat(diagnostics, " "))
@@ -202,7 +241,7 @@ M.components.git_branch = function (args)
if not vim.b.minigit_summary then return "" end
local branch = vim.b.minigit_summary.head_name or ""
- local icon = use_icons and " " or "branch: "
+ local icon = M.use_icons and " " or "branch: "
return before..icon..branch..after
end
@@ -217,9 +256,9 @@ M.components.git_status = function (args)
local status = {}
- local add_icon = use_icons and " " or "+"
- local change_icon = use_icons and " " or "~"
- local delete_icon = use_icons and " " or "-"
+ local add_icon = M.use_icons and " " or "+"
+ local change_icon = M.use_icons and " " or "~"
+ local delete_icon = M.use_icons and " " or "-"
if (summary.add or 0) > 0 then
table.insert(status, hi_pattern:format("Added", ("%s%s"):format(add_icon, summary.add)))
@@ -253,7 +292,7 @@ M.components.tab_counter = function (args)
if num_tabs == 1 then return "" end
- local icon = use_icons and "󰓩 " or "tab: "
+ local icon = M.use_icons and "󰓩 " or "tab: "
return before..icon..current_tab_index.."/"..num_tabs..after
end
@@ -281,33 +320,39 @@ M.components.markdown_word_count = function (args)
local word_count = vim.fn.wordcount().visual_words or vim.fn.wordcount().words
- return before..word_count.." words"..after
+ local icon = M.use_icons and "󱀽 " or "words: "
+
+ return before..icon..word_count..after
end
-- Setup the statusline
function M.setup(opts)
opts = opts or {}
- local statusline_components = opts.components or {
- M.components.mode({before = " "}),
- M.components.git_branch(),
- M.components.cwd(),
+ M.use_icons = opts.use_icons or false
- "%=",
+ local statusline_components = opts.components or function()
+ return {
+ M.components.mode({before = " "}),
+ M.components.git_branch(),
+ M.components.cwd(),
- M.components.session_name(),
- M.components.markdown_word_count(),
- M.components.tab_counter(),
- M.components.location({after = vim.g.neovide and " " or ""}),
- M.components.progress({after = ""}),
- }
+ "%=",
+
+ M.components.session_name(),
+ M.components.markdown_word_count(),
+ M.components.tab_counter(),
+ M.components.location({after = vim.g.neovide and " " or ""}),
+ M.components.progress(),
+ }
+ end
local gaps = opts.gaps or " "
-- Global function to construct the line
Statusline_builder = function ()
--get a table of all the statusline strings
- local statusline_strings = statusline_components
+ local statusline_strings = statusline_components()
-- Remove empty strings to prevent concat issues
for i = #statusline_strings, 1, -1 do