From a69251d52b80fe0abfaea71928cb4fc4ea579f95 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Tue, 15 Feb 2022 22:54:29 +0600 Subject: [PATCH] fix: % in filename not escaped properly. fixes #579 --- lua/lualine/components/filename.lua | 6 ++++++ lua/lualine/utils/utils.lua | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/lua/lualine/components/filename.lua b/lua/lualine/components/filename.lua index 88eff7a..a2922e4 100644 --- a/lua/lualine/components/filename.lua +++ b/lua/lualine/components/filename.lua @@ -2,6 +2,10 @@ -- MIT license, see LICENSE for more details. local M = require('lualine.component'):extend() +local modules = require('lualine_require').lazy_require { + utils = 'lualine.utils.utils', +} + local default_options = { symbols = { modified = '[+]', readonly = '[-]', unnamed = '[No Name]' }, file_status = true, @@ -44,6 +48,8 @@ M.update_status = function(self) data = vim.fn.expand('%:t') end + data = modules.utils.stl_escape(data) + if data == '' then data = self.options.symbols.unnamed end diff --git a/lua/lualine/utils/utils.lua b/lua/lualine/utils/utils.lua index b7613ad..061d11e 100644 --- a/lua/lualine/utils/utils.lua +++ b/lua/lualine/utils/utils.lua @@ -170,4 +170,11 @@ function M.retry_call_wrap(fn, times) end end +---Escape % in str so it doesn't get picked as stl item. +---@param str string +---@return string +function M.stl_escape(str) + return str:gsub('%%', '%%%%') +end + return M