Browse Source

rm no name

Thomas 1 week ago
parent
commit
4885d6ddcb
2 changed files with 31 additions and 12 deletions
  1. 31 11
      lua/config/autocmd.lua
  2. 0 1
      lua/plugins/mason.lua

+ 31 - 11
lua/config/autocmd.lua

@@ -2,19 +2,39 @@ local is_git_dir = function()
 	return os.execute("git rev-parse --is-inside-work-tree >> /dev/null 2>&1")
 end
 
+local dir_picker_group = vim.api.nvim_create_augroup("DirPicker", { clear = true })
+
 vim.api.nvim_create_autocmd("VimEnter", {
+	group = dir_picker_group,
 	callback = function()
-		local bufferPath = vim.fn.expand("%:p")
-		if vim.fn.isdirectory(bufferPath) ~= 0 then
-			vim.cmd("bdelete 1")
-			local ts_builtin = require("telescope.builtin")
-			vim.defer_fn(function()
-				if is_git_dir() == 0 then
-					ts_builtin.git_files({ show_untracked = true })
-				else
-					ts_builtin.find_files()
-				end
-			end, 10) -- 10ms delay
+		-- If launched as `nvim <dir>`, open Telescope and wipe unnamed normal buffers once a real file is opened.
+		if vim.fn.argc() == 1 then
+			local target = vim.fn.argv(0)
+			if vim.fn.isdirectory(target) == 1 then
+				vim.api.nvim_create_autocmd("BufEnter", {
+					group = dir_picker_group,
+					callback = function()
+						local buf = vim.api.nvim_get_current_buf()
+						if vim.api.nvim_buf_get_name(buf) ~= "" then
+							for _, b in ipairs(vim.api.nvim_list_bufs()) do
+								if vim.api.nvim_buf_get_name(b) == "" and vim.bo[b].buftype == "" then
+									pcall(vim.api.nvim_buf_delete, b, { force = true })
+								end
+							end
+							vim.api.nvim_del_augroup_by_id(dir_picker_group)
+						end
+					end,
+				})
+
+				local ts_builtin = require("telescope.builtin")
+				vim.defer_fn(function()
+					if is_git_dir() == 0 then
+						ts_builtin.git_files({ show_untracked = true })
+					else
+						ts_builtin.find_files()
+					end
+				end, 10)
+			end
 		end
 	end,
 })

+ 0 - 1
lua/plugins/mason.lua

@@ -11,7 +11,6 @@ return {
 			require("mason-lspconfig").setup({
 				ensure_installed = {
 					"lua_ls",
-					"rust_analyzer",
 					"tsserver",
 					"ts_ls",
 					"tinymist",