diff --git a/lua/presence/init.lua b/lua/presence/init.lua index 4fb4034..2dff2ff 100644 --- a/lua/presence/init.lua +++ b/lua/presence/init.lua @@ -72,6 +72,7 @@ local serpent = require("deps.serpent") local Discord = require("presence.discord") local file_assets = require("presence.file_assets") local file_trees = require("presence.file_trees") +local plugin_managers = require("presence.plugin_managers") function Presence:setup(options) options = options or {} @@ -87,13 +88,19 @@ function Presence:setup(options) self.log:info("Using user-defined Discord client id") end + -- General options self:set_option("auto_update", 1) - self:set_option("main_image", "neovim") - self:set_option("editing_text", self.get_status_text) - self:set_option("workspace_text", "Working on %s") - self:set_option("neovim_image_text", "The One True Text Editor") self:set_option("client_id", "793271441293967371") self:set_option("debounce_timeout", 15) + self:set_option("main_image", "neovim") + self:set_option("neovim_image_text", "The One True Text Editor") + -- Status text options + self:set_option("editing_text", "Editing %s") + self:set_option("file_tree_text", "Browsing %s") + self:set_option("git_commit_text", "Committing changes") + self:set_option("plugin_manager_text", "Managing plugins") + self:set_option("reading_text", "Reading %s") + self:set_option("workspace_text", "Working on %s") local discord_socket = self:get_discord_socket() if not discord_socket then @@ -346,19 +353,24 @@ function Presence.get_file_extension(path) end -- Get the status text for the current buffer -function Presence.get_status_text(filename) +function Presence:get_status_text(filename) if vim.bo.modifiable and not vim.bo.readonly then if vim.bo.filetype == "gitcommit" then - return string.format("Committing changes") + return string.format(self.options.git_commit_text, filename) + else + return string.format(self.options.editing_text, filename) end - return string.format("Editing %s", filename) - elseif file_trees[filename:match "[^%d]+"] then - return string.format("Browsing %s", file_trees[filename:match "[^%d]+"]) else - if vim.bo.filetype == "netrw" then - return string.format("Browsing Netrw") + local file_tree = file_trees[filename:match "[^%d]+"] + if file_tree then + return string.format(self.options.file_tree_text, file_tree) + elseif vim.bo.filetype == "netrw" then + return string.format(self.options.file_tree_text, "Netrw") + elseif plugin_managers[vim.bo.filetype] then + return string.format(self.options.plugin_manager_text, filename) + else + return string.format(self.options.reading_text, filename) end - return string.format("Reading %s", filename) end end @@ -483,13 +495,10 @@ function Presence:update_for_buffer(buffer, should_debounce) small_text = use_file_as_main_image and neovim_image_text or file_text, } - local editing_text = self.options.editing_text - editing_text = type(editing_text) == "function" - and editing_text(filename, buffer) - or string.format(editing_text, filename) + local status_text = self:get_status_text(filename) local activity = { - state = editing_text, + state = status_text, assets = assets, timestamps = { start = activity_set_at, diff --git a/lua/presence/plugin_managers.lua b/lua/presence/plugin_managers.lua new file mode 100644 index 0000000..3789ba3 --- /dev/null +++ b/lua/presence/plugin_managers.lua @@ -0,0 +1,5 @@ +-- Different plugin manager names +return { + ["packer"] = "packer", + ["vim-plug"] = "vim-plug", +}