ahmedkhalf / project.nvim

The superior project management solution for neovim.
Apache License 2.0
1.29k stars 119 forks source link

Show dotfiles but not .git #104

Open ChocolateOverflow opened 1 year ago

ChocolateOverflow commented 1 year ago

I have my own dotfiles repo with a lot of .files and .dirs (obviously) and I want project.nvim to include & show those, but I generally don't want to see the .git directory in any project. I'd like a way to show my dotfiles but not .git and the like.

diogovalentte commented 1 year ago

That would be great, hope they add an option

lonhattan007 commented 1 year ago

I tried tweaking the find_project_files function from the lua/telescope/_extensions/project.lua file like this:

local utils = require("telescope.utils")

...

local function find_project_files(prompt_bufnr)
  local project_path, cd_successful = change_working_directory(prompt_bufnr, true)
  local opt = {
    cwd = project_path,
    hidden = config.options.show_hidden,
    mode = "insert",
  }
  local _, ret, _ = utils.get_os_command_output({ "git", "rev-parse", "--is-inside-work-tree" })
  if cd_successful then
    if ret == 0 then
      builtin.git_files(opt)
    else
      builtin.find_files(opt)
    end
  end
end

It checks if the current directory is a git repo; if yes, it will use Telescope's git_files to search files, which might solve your problem. Hope this helps!

Update: I have a fork for it, you can check it out on my profile.

KnBrckr commented 5 months ago

@lonhattan007 Good tweak to allow use of git_files. I would move execution of the git command inside if cd_successful since there is no point in running the command if the cd failed.

lonhattan007 commented 3 months ago

@KnBrckr Thank you for pointing that out. I updated the code as you said.