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, callback) local canceledStr = "__INPUT_CANCELLED__" vim.ui.input({ prompt = "Title: ", cancelreturn = canceledStr, }, 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