fix: improve displayed session names
* fix: sanitize string before passing to `string.gsub(...)` fix: improve displayed paths on windows os * chore: improve scripting for reviewmain
parent
e3647c1087
commit
433e6d6808
|
|
@ -193,22 +193,42 @@ function M.toggle()
|
||||||
return M.start()
|
return M.start()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Escapes special characters before performing string substitution
|
||||||
|
---@param str string
|
||||||
|
---@param pattern string
|
||||||
|
---@param repl string|number|table|function
|
||||||
|
---@param n? integer
|
||||||
|
---@return string
|
||||||
|
---@return integer count
|
||||||
|
local function replace(str, pattern, repl, n)
|
||||||
|
pattern = string.gsub(pattern, "[%(%)%.%+%-%*%?%[%]%^%$%%]", "%%%1") -- escape pattern
|
||||||
|
repl = string.gsub(repl, "[%%]", "%%%%") -- escape replacement
|
||||||
|
return string.gsub(str, pattern, repl, n)
|
||||||
|
end
|
||||||
|
|
||||||
---List all of the sessions
|
---List all of the sessions
|
||||||
---@return table
|
---@return table
|
||||||
function M.list()
|
function M.list()
|
||||||
local save_dir = config.options.save_dir
|
local save_dir = config.options.save_dir
|
||||||
local session_files = vim.fn.glob(save_dir .. "*.vim", true, true)
|
local session_files = vim.fn.glob(save_dir .. "*.vim", true, true)
|
||||||
local branch_separator = config.options.branch_separator
|
local branch_separator = config.options.branch_separator
|
||||||
|
local dir_separator = utils.get_dir_pattern()
|
||||||
|
|
||||||
local sessions = {}
|
local sessions = {}
|
||||||
for _, session in pairs(session_files) do
|
for _, session in pairs(session_files) do
|
||||||
local session_name = session
|
local session_name = replace(session, save_dir, "")
|
||||||
:gsub(save_dir, "")
|
:gsub("%%", dir_separator)
|
||||||
:gsub("%%", utils.get_dir_pattern())
|
:gsub(vim.fn.expand("~"), dir_separator)
|
||||||
:gsub(vim.fn.expand("~"), utils.get_dir_pattern())
|
|
||||||
:gsub("//", "")
|
:gsub("//", "")
|
||||||
:sub(1, -5)
|
:sub(1, -5)
|
||||||
|
|
||||||
|
if vim.fn.has("win32") == 1 then
|
||||||
|
-- format drive letter (no trailing separator)
|
||||||
|
session_name = replace(session_name, dir_separator, ":", 1)
|
||||||
|
-- format remaining filepath separator(s)
|
||||||
|
session_name = replace(session_name, dir_separator, "\\")
|
||||||
|
end
|
||||||
|
|
||||||
local branch, dir_path
|
local branch, dir_path
|
||||||
|
|
||||||
if string.find(session_name, branch_separator, 1, true) then
|
if string.find(session_name, branch_separator, 1, true) then
|
||||||
|
|
@ -226,7 +246,6 @@ function M.list()
|
||||||
["dir_path"] = dir_path,
|
["dir_path"] = dir_path,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return sessions
|
return sessions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue