lualine.nvim icon indicating copy to clipboard operation
lualine.nvim copied to clipboard

Feat: Better integration with plugins like oil

Open 12bchl opened this issue 1 year ago • 9 comments

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.

12bchl avatar Aug 09 '23 13:08 12bchl

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

bryanboateng avatar Oct 23 '23 17:10 bryanboateng

Nope

12bchl avatar Oct 24 '23 01:10 12bchl

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

shadmansaleh avatar Oct 26 '23 05:10 shadmansaleh

Wasn't this PR supposed to add this?

My issue is that it says [No Name]

DovieW avatar Jan 14 '24 06:01 DovieW

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

DovieW avatar Jan 21 '24 19:01 DovieW

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

kjuq avatar Jan 22 '24 00:01 kjuq

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,
		},
	},

}, {})

DovieW avatar Jan 22 '24 02:01 DovieW

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
}

tronikelis avatar May 20 '24 06:05 tronikelis