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

Add context-specific status (#12)

* Add context-specific status
* Add "browsing" support for file tree explorers
* Add commit and netrw support
* Fix git commit file recognition
* Add readonly clause
This commit is contained in:
Kyle Chui 2021-05-18 02:59:58 +00:00 committed by GitHub
parent f0281ad02c
commit 2927ceb17d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

@ -0,0 +1,6 @@
-- Different neovim file tree names
return {
["NvimTree"] = "NvimTree",
["NERD_tree_"] = "NERDTree",
["[defx] default-"] = "Defx",
}

View file

@ -71,6 +71,7 @@ local msgpack = require("deps.msgpack")
local serpent = require("deps.serpent")
local Discord = require("presence.discord")
local file_assets = require("presence.file_assets")
local file_trees = require("presence.file_trees")
function Presence:setup(options)
options = options or {}
@ -88,7 +89,7 @@ function Presence:setup(options)
self:set_option("auto_update", 1)
self:set_option("main_image", "neovim")
self:set_option("editing_text", "Editing %s")
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")
@ -344,6 +345,23 @@ function Presence.get_file_extension(path)
return path:match("^.+%.(.+)$")
end
-- Get the status text for the current buffer
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")
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")
end
return string.format("Reading %s", filename)
end
end
-- Get all active local nvim unix domain socket addresses
function Presence:get_nvim_socket_addrs(on_done)
self.log:debug("Getting nvim socket addresses...")