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

feature request: Limit going beyond the project folder (change actions.parent) #541

Closed
1 task done
kelvinauta opened this issue Dec 24, 2024 · 1 comment
Closed
1 task done
Labels
enhancement New feature or request

Comments

@kelvinauta
Copy link

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

(I can contribute with this feature if it is accepted)
Currently, actions.parent goes to the parent directory without any limitation. The idea would be to change this action so that it can go, at most, to the project folder. Currently, this can be achieved by creating a custom function like this:

local oil = require("oil")
local actions = require("oil.actions")
local function is_project_root(path)
    return ( vim.fn.getcwd() == path ) or (vim.fn.getcwd() .. "/" == path)
end
local custom_parent = function()
    local current_dir = oil.get_current_dir()
    if is_project_root(current_dir) then
        vim.notify("Ya estás en la raíz del proyecto", vim.log.levels.WARN)
        return
    end
    actions.parent.callback()
end

and set in the oil configuration

-- keymaps
 ["-"] = { callback = custom_parent, mode = "n" }

Provide background

The main reason is because sometimes I accidentally go beyond the root of the project, and this can be uncomfortable. I even feel a bit scared of ruining my system files by accident or with some automation using oil. I think it would also be interesting to add an option in the config called limit_parent="cwd" with options such as cwd or root.

What is the significance of this feature?

nice to have

Additional details

If this feature is accepted, I would like to know if you have any contribution guide to be able to contribute with this.

@kelvinauta kelvinauta added the enhancement New feature or request label Dec 24, 2024
@stevearc
Copy link
Owner

To do this in any way that actually provides safety is quite difficult, as we would have to prevent editing outside the cwd from all possible edit sources. Throw symlinks in and it gets even more complicated. I don't think the benefit of this is worth the complexity of adding it to the plugin officially.

As you've discovered, it's straightforward to do a quick hack that gets you 90% of the way there. I think that works great as a user customization, but it's not robust enough for me to want to merge.

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

No branches or pull requests

2 participants