diff --git a/README.md b/README.md index 7259457..7386d5f 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ Require the plugin and call `setup` with a config table with any of the followin Presence = require("presence"):setup({ -- This config table shows all available config options with their default values auto_update = true, -- Update activity based on autocmd events (if `false`, map or manually execute `:lua Presence:update()`) - editing_text = "Editing %s", -- Editing format string (either string or function(filename, path): string) - workspace_text = "Working on %s", -- Workspace format string (either string or function(project_name, path): string) + editing_text = "Editing %s", -- Editing format string (either string or function(filename: string|nil, buffer: string): string) + workspace_text = "Working on %s", -- Workspace format string (either string or function(git_project_name: string|nil, buffer: string): string) neovim_image_text = "The One True Text Editor", -- Text displayed when hovered over the Neovim image main_image = "neovim", -- Main image display (either "neovim" or "file") client_id = "793271441293967371", -- Use your own Discord application client id (not recommended) diff --git a/lua/presence/init.lua b/lua/presence/init.lua index 372bc18..7eb4639 100644 --- a/lua/presence/init.lua +++ b/lua/presence/init.lua @@ -350,18 +350,30 @@ function Presence:update_for_buffer(buffer) }, } - -- Include project details if available + local workspace_text = self.options.workspace_text local project_name = self:get_project_name(parent_dirpath) + + -- Include project details if available if project_name then self.log:debug(string.format("Detected project: %s", project_name)) - local workspace_text = self.options.workspace_text activity.details = type(workspace_text) == "function" and workspace_text(project_name, buffer) or string.format(workspace_text, project_name) - else self.log:debug("No project detected") + + -- When no project is detected, set custom workspace text if: + -- * The custom function returns custom workspace text + -- * The configured workspace text does not contain a directive + if type(workspace_text) == "function" then + local custom_workspace_text = workspace_text(nil, buffer) + if custom_workspace_text then + activity.details = custom_workspace_text + end + elseif not workspace_text:find("%s") then + activity.details = workspace_text + end end self.discord:set_activity(activity, function(err)