Skip to content

Commit

Permalink
chore(neotree,telescope): read global and project gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
cfcosta committed Oct 24, 2024
1 parent 8a02cc6 commit 7f4f8b4
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 50 deletions.
48 changes: 24 additions & 24 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 41 additions & 11 deletions plugins/neo-tree/configuration.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
vim.g.neo_tree_remove_legacy_commands = 1

local function read_file(path)
local file = io.open(path, "r")
if not file then return nil end
local content = file:read("*all")
file:close()
return content
end

local function add_ignore(ignore_list, gitignore_content)
if gitignore_content then
for line in gitignore_content:gmatch("[^\r\n]+") do
if line ~= "" and line:sub(1, 1) ~= "#" then
table.insert(ignore_list, line)
end
end
end
end

local ignore = {
".aider.chat.history.md",
".aider.input.history",
"%.git",
".direnv",
".jj",
".obsidian",
".stfolder",
".trash",
".versions",
"node_modules",
"target"
}

-- Add global gitignore entries
local global_gitignore = read_file(os.getenv("HOME") .. "/.config/git/ignore")
add_ignore(ignore, global_gitignore)

-- Add local .gitignore entries
local local_gitignore = read_file(".gitignore")
add_ignore(ignore, local_gitignore)

require("neo-tree").setup({
window = {
position = "left",
Expand Down Expand Up @@ -39,17 +79,7 @@ require("neo-tree").setup({
"result",
},

never_show = {
".direnv",
".git",
".jj",
".obsidian",
".stfolder",
".trash",
".venv",
".versions",
"target"
},
never_show = ignore,
},
},
})
Expand Down
60 changes: 45 additions & 15 deletions plugins/telescope/configuration.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
require("telescope").load_extension("pomodori")

local telescope = require("telescope")
local actions = require("telescope.actions")
local previewers = require("telescope.previewers")
local sorters = require("telescope.sorters")

local open_with_trouble = require("trouble.sources.telescope").open
local add_to_trouble = require("trouble.sources.telescope").add

local function read_file(path)
local file = io.open(path, "r")
if not file then return nil end
local content = file:read("*all")
file:close()
return content
end

local function add_ignore(ignore_list, gitignore_content)
if gitignore_content then
for line in gitignore_content:gmatch("[^\r\n]+") do
if line ~= "" and line:sub(1, 1) ~= "#" then
table.insert(ignore_list, line)
end
end
end
end

local ignore = {
".aider.chat.history.md",
".aider.input.history",
"%.git",
".direnv",
".jj",
".obsidian",
".stfolder",
".trash",
".versions",
"node_modules",
"target"
}

-- Add global gitignore entries
local global_gitignore = read_file(os.getenv("HOME") .. "/.config/git/ignore")
add_ignore(ignore, global_gitignore)

-- Add local .gitignore entries
local local_gitignore = read_file(".gitignore")
add_ignore(ignore, local_gitignore)

local options = {
defaults = {
vimgrep_arguments = {
Expand Down Expand Up @@ -43,17 +82,7 @@ local options = {
},
find_command = { "rg", "--files", "--hidden", "--ignore-vcs" },
file_sorter = sorters.get_fuzzy_file,
file_ignore_patterns = {
"%.git",
".direnv",
".jj",
".obsidian",
".stfolder",
".trash",
".versions",
"node_modules",
"target"
},
file_ignore_patterns = ignore,
generic_sorter = sorters.get_generic_fuzzy_sorter,
path_display = { "truncate" },
winblend = 0,
Expand Down Expand Up @@ -86,8 +115,9 @@ local options = {
},
}

require("telescope").setup(options)
require("telescope").load_extension("ui-select")
telescope.setup(options)
telescope.load_extension("ui-select")
telescope.load_extension("pomodori")

vim.keymap.set(
"n",
Expand Down

0 comments on commit 7f4f8b4

Please sign in to comment.