Merge branch 'dev' into mercury

nvim: shorten path in statusline if needed
This commit is contained in:
David JULIEN 2023-02-12 22:30:58 +01:00
commit b97d011b55
Signed by: swytch
GPG Key ID: 498590A3AA82A06F

View File

@ -98,6 +98,29 @@ local function get_mode_color(m)
return color[m] return color[m]
end end
-- from https://github.com/nvim-lualine/lualine.nvim/blob/master/lua/lualine/components/filename.lua
local function shorten_path(path, max_len)
local sep = '/'
local len = #path
if len <= max_len then
return path
end
local segments = vim.split(path, sep)
for idx = 1, #segments - 1 do
if len <= max_len then
break
end
local segment = segments[idx]
local shortened = segment:sub(1, vim.startswith(segment, '.') and 2 or 1)
segments[idx] = shortened
len = len - (#segment - #shortened)
end
return table.concat(segments, sep)
end
-- from https://github.com/nvim-lua/lsp-status.nvim/blob/master/lua/lsp-status/diagnostics.lua -- from https://github.com/nvim-lua/lsp-status.nvim/blob/master/lua/lsp-status/diagnostics.lua
local function get_lsp_diagnostics() local function get_lsp_diagnostics()
local result = {} local result = {}
@ -138,14 +161,16 @@ end
end end
local function statusline_focused() local function statusline_focused()
local file = vim.fn.expand("%:p:~")
local diagnostics = get_lsp_diagnostics() local diagnostics = get_lsp_diagnostics()
local mode = vim.fn.mode() local mode = vim.fn.mode()
local mg = get_mode(mode) local mg = get_mode(mode)
local accent_color = get_mode_color(mg) local accent_color = get_mode_color(mg)
local winwidth = vim.fn.winwidth(0)
local left = table.concat { local left = table.concat {
gen_section(accent_color, { get_mode_display_name(mg) }), gen_section(accent_color, { get_mode_display_name(mg) }),
gen_section("%#Middle#", {"%f"}), gen_section("%#Middle#", { shorten_path(file, winwidth / 3) }),
gen_section("%#Bottom#", { "%m", "%r" }), gen_section("%#Bottom#", { "%m", "%r" }),
gen_section( gen_section(
"%#Alert#", "%#Alert#",