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

Add change directory functionality to file browser & find files #644

Closed
wants to merge 13 commits into from
Closed

Add change directory functionality to file browser & find files #644

wants to merge 13 commits into from

Conversation

ranjithshegde
Copy link

Just a small piece of lua code to change nvim's pwd while using the builtin file_browser
Navigate to the directory and type (capitol) C in normal mode

@kkharji
Copy link
Member

kkharji commented Mar 12, 2021

Hey @ranjithshegde, could you please fix indentation to using two space per-tab and force push before conni sees this 😆 .

Thanks

@oberblastmeister
Copy link
Contributor

I would prefer the mapping cd because it reflects what you are doing and also doesn't override a default vim mapping.

@ranjithshegde
Copy link
Author

I would prefer the mapping cd because it reflects what you are doing and also doesn't override a default vim mapping.

Done

@oberblastmeister
Copy link
Contributor

Nice. Can you add this into an action so it can be used by other finders such as find_files?

@ranjithshegde
Copy link
Author

Nice. Can you add this into an action so it can be used by other finders such as find_files?

I will try tomorrow. Will be a bit tricky for find_files..etc as this function gets the value when the selection is a directory, not a file.

@ranjithshegde
Copy link
Author

Tried to rebase to master, had forgotten about this PR. Will get to it this weekend

@ranjithshegde
Copy link
Author

Nice. Can you add this into an action so it can be used by other finders such as find_files?

Just did. Please let me know how that looks to you. Sorry this took a while, busy with my thesis

@ranjithshegde ranjithshegde changed the title Add change directory functionality to file browser Add change directory functionality to file browser & find files Jul 8, 2021
change lcd to cd.
lcd only affects TelescopePrompt buffer
@ranjithshegde
Copy link
Author

@Conni2461
Any comments? do you approve?

Copy link
Member

@Conni2461 Conni2461 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically the code looks good, documentation would be nice, like so

But i personally have a couple of issues with this. This is too opinionated and too easy that people could just pass in opts.attach_mappings function to their function call. Couple of issue:

Its mapped, and people cant change this mapping because both are local functions.

cd vs lcd vs tcd whats correct for what workflow. lcd is not much harder to implement. You just need the previous bufnr and then you can do vim.api.nvim_buf_call(bufnr, function() lcd_here end) but i personally only do tcd and a lot of other people will feel like that.

Idk what to say, i know you spent time on it.
And also this is just my opinion, maybe other people like tami or ober see it differently. They at least started reviewing this PR 😆

@Conni2461
Copy link
Member

I added it as configuration Recipes and created you: https://github.com/nvim-telescope/telescope.nvim/wiki/Configuration-Recipes#change-directory

I think this works better. Still thanks for you work tho :)

@Conni2461 Conni2461 closed this Dec 4, 2021
@ranjithshegde
Copy link
Author

It is indeed better as a config recipe than a PR. Besides I see that the file browser itself might be removed from core!
Thanks @Conni2461.

@KodyVB
Copy link

KodyVB commented May 12, 2022

@Conni2461 I couldn't get it to work how the recipe showed, as the mappings were under pickers --> find_files --> mappings, while mappings are usually under defaults --> mappings. Moving them to match what's shown below made it work for me, so I'm wondering if the recipe should be updated to match that. Sorry if bringing this up in a comment on a closed request isn't the proper way to do it or whatever - I don't have much experience with this kind of stuff.

require("telescope").setup({
  defaults = {
    -- ....
    mappings = {
      n = {
        ["cd"] = function(prompt_bufnr)
          local selection = require("telescope.actions.state").get_selected_entry()
          local dir = vim.fn.fnamemodify(selection.path, ":p:h")
          require("telescope.actions").close(prompt_bufnr)
          -- Depending on what you want put `cd`, `lcd`, `tcd`
          vim.cmd(string.format("silent lcd %s", dir))
        end,
      },
    },
  },
})

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

Successfully merging this pull request may close these issues.

6 participants