aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorame <[email protected]>2025-08-31 14:47:14 -0500
committerame <[email protected]>2025-08-31 14:47:14 -0500
commit3f5d8d8f62e90d205f4e8ccf14dd434d0f3bd3eb (patch)
tree609049b7a54e38b1150455a724fb3dc6e9646911 /lua
parent6e5735049ebf19e77f70c6609dec629870de973a (diff)
lsp and oil changes!!HEADmain
Diffstat (limited to 'lua')
-rw-r--r--lua/lua/oil-gitignore.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/lua/lua/oil-gitignore.lua b/lua/lua/oil-gitignore.lua
new file mode 100644
index 0000000..a63eaf0
--- /dev/null
+++ b/lua/lua/oil-gitignore.lua
@@ -0,0 +1,54 @@
+--https://github.com/stevearc/oil.nvim/blob/master/doc/recipes.md#hide-gitignored-files-and-show-git-tracked-hidden-files
+
+local M = {}
+
+-- helper function to parse output
+function M.parse_output(proc)
+ local result = proc:wait()
+ local ret = {}
+ if result.code == 0 then
+ for line in vim.gsplit(result.stdout, "\n", { plain = true, trimempty = true }) do
+ -- Remove trailing slash
+ line = line:gsub("/$", "")
+ ret[line] = true
+ end
+ end
+ return ret
+end
+
+-- build git status cache
+function M.new_git_status()
+ return setmetatable({}, {
+ __index = function(self, key)
+ local ignore_proc = vim.system(
+ { "git", "ls-files", "--ignored", "--exclude-standard", "--others", "--directory" },
+ {
+ cwd = key,
+ text = true,
+ }
+ )
+ local tracked_proc = vim.system({ "git", "ls-tree", "HEAD", "--name-only" }, {
+ cwd = key,
+ text = true,
+ })
+ local ret = {
+ ignored = M.parse_output(ignore_proc),
+ tracked = M.parse_output(tracked_proc),
+ }
+
+ rawset(self, key, ret)
+ return ret
+ end,
+ })
+end
+M.git_status = M.new_git_status()
+
+-- Clear git status cache on refresh
+M.refresh = require("oil.actions").refresh
+M.orig_refresh = M.refresh.callback
+M.refresh.callback = function(...)
+ git_status = M.new_git_status()
+ M.orig_refresh(...)
+end
+
+return M