[nvim] feat: replace path in statusline by "/.../" when useful
This commit is contained in:
parent
34dc364d9f
commit
85b4b08824
@ -107,7 +107,13 @@ local function shorten_path(path, max_len)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local segments = vim.split(path, sep)
|
local segments = vim.split(path, sep)
|
||||||
for idx = 1, #segments - 1 do
|
local start = 1
|
||||||
|
if segments[1] == "~" then
|
||||||
|
start = start + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
for idx = start, #segments - 1 do
|
||||||
if len <= max_len then
|
if len <= max_len then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -122,6 +128,13 @@ local function shorten_path(path, max_len)
|
|||||||
len = len - (#segment - #shortened)
|
len = len - (#segment - #shortened)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (len > max_len and #segments > 3) then
|
||||||
|
while (len > max_len and #segments > 3) do
|
||||||
|
table.remove(segments, 2)
|
||||||
|
end
|
||||||
|
table.insert(segments,2, "...")
|
||||||
|
end
|
||||||
|
|
||||||
return table.concat(segments, sep)
|
return table.concat(segments, sep)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -174,7 +187,7 @@ local function statusline_focused()
|
|||||||
|
|
||||||
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#", { shorten_path(file, winwidth / 3) }),
|
gen_section("%#Middle#", { shorten_path(file, winwidth / 2) }),
|
||||||
gen_section("%#Bottom#", { "%m", "%r" }),
|
gen_section("%#Bottom#", { "%m", "%r" }),
|
||||||
gen_section(
|
gen_section(
|
||||||
"%#Alert#",
|
"%#Alert#",
|
||||||
@ -223,7 +236,7 @@ local function statusline_not_focused()
|
|||||||
local winwidth = vim.fn.winwidth(0)
|
local winwidth = vim.fn.winwidth(0)
|
||||||
return table.concat {
|
return table.concat {
|
||||||
gen_section("%#StatuslineNF#", {
|
gen_section("%#StatuslineNF#", {
|
||||||
shorten_path(file, winwidth / 3),
|
shorten_path(file, winwidth / 2),
|
||||||
"%m"
|
"%m"
|
||||||
}),
|
}),
|
||||||
"%=",
|
"%=",
|
||||||
|
Reference in New Issue
Block a user