1
0
Fork 0
mirror of https://github.com/jiriks74/presence.nvim synced 2024-12-28 11:02:34 +01:00

Use workspace text option when no project is detected

This commit is contained in:
Andrew Kwon 2021-03-08 18:56:53 -08:00
parent 0537801065
commit 9162582eb6
2 changed files with 17 additions and 5 deletions

View file

@ -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)

View file

@ -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)