nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
5.75k stars 457 forks source link

Feat: Better integration with plugins like oil #1077

Open 12bchl opened 11 months ago

12bchl commented 11 months ago

Requested feature

With oil set as default explorer, when you jump out to current dir, you will be in a remote oil buffer. This means you are outside your git repo and your filename will be of the form oil://home/user/gitFolder/repoFolder/subDir...

This is pretty gross. Unfortunately the oil team did not have any solution.

I really like the branch and filename section types. And I use the diff symbols regularly when editting oil buffers. I'd just like to have my repo section and filename section working sensibly with oil directory buffers.

The filetype is recognized as "oil", so I'm wondering if it is possible to override the branch string and filename string receivers for given filetypes? I think it would be a pretty extensible feature and useful for other things too, maybe helpful with ssh.

Motivation

Sane & expected lualine appearance with oil or other plugins that do not operate directly in the apparent cwd.

bryanboateng commented 8 months ago

Where you able to find some sort of solution to this problem?

12bchl commented 8 months ago

Nope

shadmansaleh commented 8 months ago

You can use the fmt option to transform result of a component before it gets displayed.

So in this case you can set fmt option on branch and filename component to a function that gets rid of the things that don't need to be show from result of these component in case of oil filetype.

A bit of filetype check and pattern matching should be enough.

the fmt funciton will get the result of the component as it's argument and what ever the function returns will be rendered in lualine.

image

https://github.com/nvim-lualine/lualine.nvim#general-component-options

DovieW commented 6 months ago

Wasn't this PR supposed to add this?

My issue is that it says [No Name]

DovieW commented 5 months ago

@kjuq Would you be able to weigh in on why we can't get the path to show? All plugins are up to date (using lazy.nvim) and I can see the oil.lua file you created in my filesystem. In my case it always says [No Name]

kjuq commented 5 months ago

@DovieW Could you send me a minimal configuration, which probably enables only lualine and oil, to reproduce the issue? In my environment, the path is shown properly.

DovieW commented 5 months ago

Thanks for responding @kjuq.

I was able to get the old oil:/// path instead of [No Name]. It seems that having ANY options defined in the lualine config, causes the [No Name] path. The entire opts block has to be commented it out. .... Ok, so I'm not sure why the above was happening, but I'm now realizing that I needed the extensions config. It works now as you intended.

See example config below using lazy.nvim for anyone that finds this.

local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system {
        'git',
        'clone',
        '--filter=blob:none',
        'https://github.com/folke/lazy.nvim.git',
        '--branch=stable', -- latest stable release
        lazypath,
    }
end
vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
    {
        'nvim-lualine/lualine.nvim',
        opts = {
            options = {
                theme = 'auto',
            },
            extensions = { 'oil' }
        }
    },
    {
        'stevearc/oil.nvim',
        opts = {
            default_file_explorer = true,
        },
    },

}, {})
Tronikelis commented 1 month ago

just want to note here that in the oil buffer, the branch name is empty and not shown

this is the part that gets the incorrect dir

https://github.com/nvim-lualine/lualine.nvim/blob/0a5a66803c7407767b799067986b4dc3036e1983/lua/lualine/components/branch/git_branch.lua#L78

I think lualine should somehow expose certain apis like get_current_dir globally and then we could modify it to return oil dir on oil filetypes

So then we could pass in the config

{
    get_current_dir = function()
        if vim.bo.filetype == "oil" then
            return require(oil).get_current_dir()
        end
        -- else fallback    
    end
}