chore(utils): reorganize utils

This commit is contained in:
Thomas Lambert
2023-04-28 22:57:41 +02:00
parent 9d2e4fd1e1
commit 88d9344b41
8 changed files with 2853 additions and 2853 deletions

View File

@@ -0,0 +1,32 @@
local M = {}
-- strip an extension from a file name, escaping "." properly, eg:
-- strip_extension("path/Filename.md", ".md") -> "path/Filename"
local function strip_extension(str, ext)
return str:gsub("(" .. ext:gsub("%.", "%%.") .. ")$", "")
end
function M.prompt_title(ext, defaultFile, callback)
local canceledStr = "__INPUT_CANCELLED__"
vim.ui.input({
prompt = "Title: ",
cancelreturn = canceledStr,
completion = "file",
default = defaultFile,
}, function(title)
if not title then
title = ""
end
if title == canceledStr then
vim.cmd("echohl WarningMsg")
vim.cmd("echomsg 'Note creation cancelled!'")
vim.cmd("echohl None")
else
title = strip_extension(title, ext)
callback(title)
end
end)
end
return M