Skip to content

Commit

Permalink
improv: notification formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Sep 21, 2023
1 parent c1e370f commit 52ebc1d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lua/tinygit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 52ebc1d

Please sign in to comment.