GnikDroy / projections.nvim

A map to your filesystem
GNU General Public License v3.0
236 stars 8 forks source link

[Feature Request] I think we can have a indicator in the statusline #8

Closed nyngwang closed 1 year ago

nyngwang commented 1 year ago

...(or somewhere) to show:

  1. An icon so that we can know that the session is working.
  2. Some text about the session: the name/path/id/etc of the session file.
  3. (and more)

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.

GnikDroy commented 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.

  1. There are a lot of statusline plugins. And I need to ship code for quite a few of them. lualine, galaxyline, neoline, bubbly etc..
  2. Some plugins like lualine have extension code in their own repository. So, the following snippet would be present in lualine, not in projections
  3. There is no way to make sure that everyone is satisfied. Some might want icons only, some might want project name, session path, a different icon maybe?, etc

What I can do is create a wiki entry where I document this snippet for future users.

Edit: wiki link