-
Notifications
You must be signed in to change notification settings - Fork 141
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
readme.md addition request: add example of is_always_hidden of .gitignore targets and .git folder #92
Comments
So it appears my installation just bugged, had to remove it from plugins section and do PackerSync and add it back for the config to work, that was really weird, probably packer problem? I mean the is_always_hidden still doesn't work but other things like columns didn't work before doing this. |
Is this caused by my implementation? #69 I'm busy these days so no immediate reply. You could still take a look at the PR first and tag/ping me when necessary, I will take a look. And sorry in advance if anything I did wrong. Linked for convenience: Lines 16 to 20 in 4738d08
|
Hi, I tried it again today and found out that I can't different folder from file in the is_always_hidden. |
If I understand you correctly, you want all gitignored files to be hidden? That's going to be pretty involved. You'll need to find the |
@Arisa-Snowbell I would suggest changing the way we think:
That is: use two separate plugins for two different views({file,buf}tree, git). This way we can reduce/remove the burden of maintaining git from the authors of {file,buf}tree-like plugins. I know that the configuration of fzf-lua might look a little intimidating, but they provided Profiles(probably months ago?) to help you start quick by sane defaults. I have been using it for two years, so I recommend it for you, sincerely. (I used to be a user of neo-tree and they provide some |
Closing as writing gitignore parsing logic is out of scope. The methodology is laid out, but the implementation is left as an exercise for the reader. |
For future readers who wish to git ignore files :). This uses LazyVim I added a cache to avoid rerunning the git command for each file. You can remove that part and call the function directly, but it's much slower. The cache will run the command once and store the result. Then subsequent runs will just check against the cached result. -- nvim/lua/plugins/oil.lua
-- @class GitCache
-- @field func function
-- @field results table
local GitCache = {}
-- @param func function
-- @return GitCache
function GitCache:new(func)
local tbl = {
func = func,
results = {}
}
self.__index = self
setmetatable(tbl, self)
return tbl
end
-- @param dir string
function GitCache:_call(dir)
local cmd = string.format('git -C %s ls-files --ignored --exclude-standard --others --directory | grep -v \"/.*\\/\"', dir)
local handle = io.popen(cmd)
if handle == nil then
return
end
-- Clean the output a bit
local lines = vim.split(output, '\n')
local ignored_files = {}
for _, line in ipairs(lines) do
-- Remove trailing slash
line = line:gsub('/$', '')
table.insert(ignored_files, line)
end
table.insert(ignored_files, '.git')
table.insert(ignored_files, '..')
self.results[dir] = ignored_files
self.checked = true
end
-- @param dir string
-- @return table
function GitCache:call(dir)
if self.results[dir] == nil then
-- Reset cache, we don't care about old dir results
self.results = {}
self:_call(dir)
end
return self.results[dir]
end
local cache = GitCache:new(get_ignored)
return {
'stevearc/oil.nvim',
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
local oil = require('oil')
oil.setup({
view_options = {
is_hidden_file = function(name, _)
local ignored_files = cache:call(oil.get_current_dir())
return vim.tbl_contains(ignored_files, name)
end,
},
})
end
} |
Hello! Thanks @dmelchor-stripe I slightly changed your implementation: local function get_git_ignored_files_in(dir)
local found = vim.fs.find(".git", {
upward = true,
path = dir,
})
if #found == 0 then
return {}
end
local cmd = string.format(
'git -C %s ls-files --ignored --exclude-standard --others --directory | grep -v "/.*\\/"',
dir
)
local handle = io.popen(cmd)
if handle == nil then
return
end
local ignored_files = {}
for line in handle:lines "*l" do
line = line:gsub("/$", "")
table.insert(ignored_files, line)
end
handle:close()
return ignored_files
end Here it is in my config: https://github.com/IlyasYOY/dotfiles/blob/419ff681f49372d6b75174c95fa0f17afa021966/config/nvim/lua/plugins/core.lua#L1 Usage of the function: view_options = {
show_hidden = true,
is_hidden_file = function(name, bufnr)
local ignored_files =
get_git_ignored_files_in(oil.get_current_dir())
return vim.tbl_contains(ignored_files, name)
or vim.startswith(name, ".")
end,
}, Here it is in my config: https://github.com/IlyasYOY/dotfiles/blob/419ff681f49372d6b75174c95fa0f17afa021966/config/nvim/lua/plugins/core.lua#L74 |
Daniel's approach seem most sane. If we want to filter by |
Updated my comment so it now works ourside of @Rizhiy you might be interested in it you borrowed the solution |
Great! |
I've added this as a recipe in the new recipes section of the documentation |
Did you check existing requests?
Describe the feature
An example of is_always_hidden function that reads .gitignore and hides the targets in the file with a .git folder.
Provide background
It's very common practice and not everyone is able to create such a function by themselves. I would appreciate that very much.
I tried but failed miserably, it didn't react at all, doesn't matter if I return true or false, it was weird.
Additional details
No response
The text was updated successfully, but these errors were encountered: