Closed nyngwang closed 1 year ago
Session.info()
is the function you are looking for.
-- Returns the path of the session file as well as project information
-- Returns nil if path is not a valid project path
-- @args spath The path to project root
-- @returns nil | path of session file and project information
function Session.info(spath) ... end
So, suppose if you want to display project name in your status line,
local project_name_display = function ()
local projections_available, Session = pcall(require, 'projections.session')
if projections_available then
local info = Session.info(vim.loop.cwd())
if info ~= nil then
-- local session_file_path = tostring(info.path)
-- local project_workspace_patterns = info.project.workspace.patterns
-- local project_workspace_path = tostring(info.project.workspace)
local project_name = info.project.name
return '🮮 ' .. project_name -- you can also just return an icon here.
end
end
return vim.fs.basename(vim.loop.cwd())
end
Now depending on your status line plugin, you can use this function. For example with lualine.
require('lualine').setup({
sections = { lualine_c = { { project_name_display } } }
})
Now regarding if I can ship with some of this code. There are some major problems.
lualine, galaxyline, neoline, bubbly etc..
lualine
have extension code in their own repository. So, the following snippet would be present in lualine, not in projections
What I can do is create a wiki entry where I document this snippet for future users.
Edit: wiki link
...(or somewhere) to show:
This idea comes from reading the post. (The author did provide a link to his repo but I haven't read the code.)
Feel free to close it if this is not a good idea :) But if you're interested in it, then I think point 1. should have higher priority than point 2., since I cannot always remember whether or not I'm currently in a project directory.