diff --git a/lua/tinygit.lua b/lua/tinygit.lua index ab9159b..4b0e45f 100644 --- a/lua/tinygit.lua +++ b/lua/tinygit.lua @@ -48,12 +48,14 @@ local function openUrl(url) end ---send notification ----@param msg string +---@param body string ---@param level? "info"|"trace"|"debug"|"warn"|"error" -local function notify(msg, level) +---@param titleAppendix? string +local function notify(body, level, titleAppendix) local pluginName = "tinygit" if not level then level = "info" end - vim.notify(vim.trim(msg), vim.log.levels[level:upper()], { title = pluginName }) + local title = titleAppendix and pluginName .. " – " .. titleAppendix or pluginName + vim.notify(vim.trim(body), vim.log.levels[level:upper()], { title = title }) end ---checks if last command was successful, if not, notify @@ -178,9 +180,9 @@ function M.amendNoEdit(opts) local stderr = fn.system { "git", "commit", "--amend", "--no-edit" } if nonZeroExit(stderr) then return end - local msg = ('󰊢 Amend-No-Edit\n"%s"'):format(lastCommitMsg) - if opts.forcePush then msg = msg .. "\n\nForce Pushing…" end - notify(msg) + local body = ('"%s"'):format(lastCommitMsg) + if opts.forcePush then body = body .. "\nForce Pushing…" end + notify(body, "info", "Amend-No-edit") if opts.forcePush then M.push { force = true } end end @@ -209,9 +211,9 @@ function M.amendOnlyMsg(opts, prefillMsg) local stderr = fn.system { "git", "commit", "--amend", "-m", newMsg } if nonZeroExit(stderr) then return end - local msg = ('󰊢 Amend\n"%s"'):format(newMsg) - if opts.forcePush then msg = msg .. "\n\nForce Pushing…" end - notify(msg) + local body = ('"%s"'):format(newMsg) + if opts.forcePush then body = body .. "\nForce Pushing…" end + notify(body, "info", "Amend-Only-Msg") if opts.forcePush then M.push { force = true } end end) @@ -247,9 +249,9 @@ function M.smartCommit(opts, prefillMsg) local stderr = fn.system { "git", "commit", "-m", newMsg } if nonZeroExit(stderr) then return end - local msg = ('󰊢 Smart Commit\n"%s"'):format(newMsg) - if opts.push then msg = msg .. "\n\nPushing…" end - notify(msg) + local body = ('"%s"'):format(newMsg) + if opts.push then body = body .. "\nPushing…" end + notify(body, "info", "Smart-Commit") if opts.push then M.push { pullBefore = true } end end)