diff --git a/lua/github-presence/init.lua b/lua/github-presence/init.lua deleted file mode 100644 index c9e68a9..0000000 --- a/lua/github-presence/init.lua +++ /dev/null @@ -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 diff --git a/lua/github_presence/autoload.lua b/lua/github_presence/autoload.lua new file mode 100644 index 0000000..4c3a790 --- /dev/null +++ b/lua/github_presence/autoload.lua @@ -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 diff --git a/lua/github_presence/config.lua b/lua/github_presence/config.lua new file mode 100644 index 0000000..836275f --- /dev/null +++ b/lua/github_presence/config.lua @@ -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 diff --git a/lua/github_presence/github.lua b/lua/github_presence/github.lua new file mode 100644 index 0000000..1c34413 --- /dev/null +++ b/lua/github_presence/github.lua @@ -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 diff --git a/lua/github_presence/init.lua b/lua/github_presence/init.lua new file mode 100644 index 0000000..fb6d583 --- /dev/null +++ b/lua/github_presence/init.lua @@ -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 diff --git a/lua/github_presence/notify.lua b/lua/github_presence/notify.lua new file mode 100644 index 0000000..b28ae07 --- /dev/null +++ b/lua/github_presence/notify.lua @@ -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 diff --git a/lua/github_presence/timer.lua b/lua/github_presence/timer.lua new file mode 100644 index 0000000..7df923d --- /dev/null +++ b/lua/github_presence/timer.lua @@ -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, +} diff --git a/lua/github_presence/updates.lua b/lua/github_presence/updates.lua new file mode 100644 index 0000000..17feab4 --- /dev/null +++ b/lua/github_presence/updates.lua @@ -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