Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Better integration with plugins like oil #1077

Open
12bchl opened this issue Aug 9, 2023 · 10 comments
Open

Feat: Better integration with plugins like oil #1077

12bchl opened this issue Aug 9, 2023 · 10 comments
Labels
new feature New feature or feature request

Comments

@12bchl
Copy link

12bchl commented Aug 9, 2023

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 12bchl added the new feature New feature or feature request label Aug 9, 2023
@bryanboateng
Copy link

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

@12bchl
Copy link
Author

12bchl commented Oct 24, 2023

Nope

@shadmansaleh
Copy link
Member

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
Copy link

DovieW commented Jan 14, 2024

Wasn't this PR supposed to add this?

My issue is that it says [No Name]

@DovieW
Copy link

DovieW commented Jan 21, 2024

@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
Copy link
Contributor

kjuq commented Jan 22, 2024

@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
Copy link

DovieW commented Jan 22, 2024

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
Copy link
Contributor

tronikelis commented May 20, 2024

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

local file_dir = dir_path or vim.fn.expand('%:p:h')

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
Copy link
Contributor

Sorry for the ping but I opened this PR #1298 which adds filename component support for oil.nvim

@cgimenes
Copy link

Should't this #1242 be inside the oil extension?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or feature request
Projects
None yet
Development

No branches or pull requests

7 participants