refactor(git): extract util.split_lines helper
This commit is contained in:
@@ -428,4 +428,17 @@ function M.get_hl_source(name)
|
||||
return hl
|
||||
end
|
||||
|
||||
---Split a string on newlines, dropping the trailing empty element that an
|
||||
---input ending in `\n` produces. Convenient for slicing subprocess stdout
|
||||
---into a list of lines without a phantom blank at the end.
|
||||
---@param content string
|
||||
---@return string[]
|
||||
function M.split_lines(content)
|
||||
local lines = vim.split(content, "\n", { plain = true, trimempty = false })
|
||||
if #lines > 0 and lines[#lines] == "" then
|
||||
table.remove(lines)
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user