with status update

This commit is contained in:
Kasper Juul Hermansen 2022-10-13 22:19:21 +02:00
parent 90fac0d1ef
commit 635eac655b
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
8 changed files with 105 additions and 13 deletions

View File

@ -1,13 +0,0 @@
local GitHubPresence = {}
GitHubPresence.setup = {}
function GitHubPresence:setup(options)
options = options or {}
self.options = options
vim.schedule(
function() vim.notify(string.format([[echom "[%s] %s"]], "github-presence", "initialized")) end
)
end
return GitHubPresence

View File

@ -0,0 +1,16 @@
local create = vim.api.nvim_create_augroup
local define = vim.api.nvim_create_autocmd
local M = {}
create("github_presence_autocmds", { clear = true })
function M.setup()
define({ "BufEnter" }, {
group = "github_presence_autocmds",
pattern = { "*" },
callback = function() require("github_presence.updates").set_status() end,
})
end
return M

View File

@ -0,0 +1,14 @@
local M = {}
M.defaults = {}
local config = {}
function M.setup(user_config)
user_config = user_config or {}
config = vim.tbl_deep_extend("force", M.defaults, user_config)
return config
end
return M

View File

@ -0,0 +1,13 @@
local notify = require "github_presence.notify"
local M = {}
function M.set_status(activity)
if activity == nil then return end
local _ = vim.fn.systemlist(
string.format("github-status --message 'Currently editting: %s'", activity.file)
)
notify.info "set status"
end
return M

View File

@ -0,0 +1,13 @@
local notify = require "github_presence.notify"
local M = {}
function M.setup(options)
require("github_presence.autoload").setup()
require("github_presence.updates").setup()
require("github_presence.config").setup(options)
require("github_presence.timer").start_cron()
end
return M

View File

@ -0,0 +1,17 @@
local M = {}
---@param message string
function M.info(message)
vim.schedule(
function() vim.notify(string.format("[%s]: %s", "github-presence", message), "info") end
)
end
---@param message string
function M.debug(message)
vim.schedule(
function() vim.notify(string.format("[%s]: %s", "github-presence", message), "debug") end
)
end
return M

View File

@ -0,0 +1,13 @@
local github = require "github_presence.github"
local updates = require "github_presence.updates"
return {
start_cron = function()
local timer = vim.loop.new_timer()
timer:start(
1000,
1000 * 60,
vim.schedule_wrap(function() github.set_status(updates.last_activity) end)
)
end,
}

View File

@ -0,0 +1,19 @@
local M = {}
M.last_activity = {}
function M.setup() end
function M.set_status()
local current_buffer = vim.api.nvim_get_current_buf()
local buf_name = vim.api.nvim_buf_get_name(current_buffer)
local file_name = buf_name:match(string.format("^.+%s(.+)$", "/"))
if file_name == nil then return end
if file_name == M.last_activity.file then return end
M.last_activity = {
file = file_name,
set_at = os.time(),
}
end
return M