From 21617a9d602f2400c8e9813490958e106cb88ca8 Mon Sep 17 00:00:00 2001 From: dotfrag <17456867+dotfrag@users.noreply.github.com> Date: Mon, 10 Jun 2024 23:06:09 +0300 Subject: [PATCH] feat(lualine): show readonly icon (#3567) Adds a configurable lock icon when a file is opened as read only. Mimics `vi -R ` status line. --- lua/lazyvim/util/lualine.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/util/lualine.lua b/lua/lazyvim/util/lualine.lua index 3e546873..aad22677 100644 --- a/lua/lazyvim/util/lualine.lua +++ b/lua/lazyvim/util/lualine.lua @@ -72,7 +72,7 @@ function M.format(component, text, hl_group) return component:format_hl(lualine_hl_group) .. text .. component:get_default_hl() end ----@param opts? {relative: "cwd"|"root", modified_hl: string?, directory_hl: string?, filename_hl: string?} +---@param opts? {relative: "cwd"|"root", modified_hl: string?, directory_hl: string?, filename_hl: string?, modified_sign: string?, readonly_icon: string?, length: number?} function M.pretty_path(opts) opts = vim.tbl_extend("force", { relative = "cwd", @@ -80,6 +80,7 @@ function M.pretty_path(opts) directory_hl = "", filename_hl = "Bold", modified_sign = "", + readonly_icon = " 󰌾 ", length = 3, }, opts or {}) @@ -120,7 +121,12 @@ function M.pretty_path(opts) dir = table.concat({ unpack(parts, 1, #parts - 1) }, sep) dir = M.format(self, dir .. sep, opts.directory_hl) end - return dir .. parts[#parts] + + local readonly = "" + if vim.bo.readonly then + readonly = M.format(self, opts.readonly_icon, opts.modified_hl) + end + return dir .. parts[#parts] .. readonly end end