From 42647db6d2cd08e306f233e0cfae60804c68b1fa Mon Sep 17 00:00:00 2001 From: Daniel Carrillo Date: Fri, 14 Jun 2024 18:17:02 +0200 Subject: [PATCH] [neovim] Move utils to a external file --- .config/nvim/lazy-lock.json | 24 ++++++------- .config/nvim/lua/core/lazy.lua | 40 +-------------------- .config/nvim/lua/plugins/init.lua | 1 + .config/nvim/lua/plugins/neovim-project.lua | 19 ++++++++++ .config/nvim/lua/util/files.lua | 10 ++++++ 5 files changed, 43 insertions(+), 51 deletions(-) create mode 100644 .config/nvim/lua/plugins/neovim-project.lua create mode 100644 .config/nvim/lua/util/files.lua diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 7b2c333..81c2615 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -7,23 +7,23 @@ "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, - "conform.nvim": { "branch": "master", "commit": "07d1298739cd7c616cb683bfd848f6b369f93297" }, + "conform.nvim": { "branch": "master", "commit": "797d1f622a23d4a21bb58218bdf5999a9beac4ef" }, "copilot-cmp": { "branch": "master", "commit": "72fbaa03695779f8349be3ac54fa8bd77eed3ee3" }, "copilot-lualine": { "branch": "main", "commit": "4cca52f4d4d6c7439c51227d8054e346ef5ff0e0" }, "copilot.lua": { "branch": "master", "commit": "f7612f5af4a7d7615babf43ab1e67a2d790c13a6" }, "copilotchat.nvim": { "branch": "canary", "commit": "82923efe22b604cf9c0cad0bb2a74aa9247755ab" }, - "diffview.nvim": { "branch": "main", "commit": "3afa6a053f680e9f1329c4a151db988a482306cd" }, + "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, "fzy-lua-native": { "branch": "master", "commit": "820f745b7c442176bcc243e8f38ef4b985febfaf" }, "git-blame.nvim": { "branch": "master", "commit": "408d5487d908dfe5d48e5645d8b27ddcc16b11e0" }, "github-nvim-theme": { "branch": "main", "commit": "d832925e77cef27b16011a8dfd8835f49bdcd055" }, - "gitsigns.nvim": { "branch": "main", "commit": "76927d14d3fbd4ba06ccb5246e79d93b5442c188" }, + "gitsigns.nvim": { "branch": "main", "commit": "0b04035bb7b3c83e999b9676e2fb46fd0aa9f910" }, "go.nvim": { "branch": "master", "commit": "8f8ab4b968d08bd70ecda1f2909fb5e6177452ca" }, "grug-far.nvim": { "branch": "main", "commit": "23a645089bd3fa75412babe9b9b3dc2b795f2e89" }, "guihua.lua": { "branch": "master", "commit": "225db770e36aae6a1e9e3a65578095c8eb4038d3" }, "indent-blankline.nvim": { "branch": "master", "commit": "d98f537c3492e87b6dc6c2e3f66ac517528f406f" }, "karen-yank.nvim": { "branch": "main", "commit": "817f50c9464ce557c8f7f8f4d4c8d2f7b81fc40c" }, "lazy.nvim": { "branch": "main", "commit": "eb4957442e3182f051b0ae11da32e06d22c190e3" }, - "leap.nvim": { "branch": "main", "commit": "0d15057cc47fa49f6609bf364f5ad3842f08c58c" }, + "leap.nvim": { "branch": "main", "commit": "24935d06c7e06bf8929feb24a3525cd128fc0cc4" }, "logstash.vim": { "branch": "master", "commit": "531fe079e8c964d2b5786bcb5871c72f966adc2a" }, "lspsaga.nvim": { "branch": "main", "commit": "6f920cfabddb9b7de5a3a4d0b7cd4f0774ae23e2" }, "lualine-lsp-progress": { "branch": "master", "commit": "56842d097245a08d77912edf5f2a69ba29f275d7" }, @@ -31,16 +31,16 @@ "markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "37a336b653f8594df75c827ed589f1c91d91ff6c" }, "mason.nvim": { "branch": "main", "commit": "0950b15060067f752fde13a779a994f59516ce3d" }, - "mini.align": { "branch": "main", "commit": "f845218c5fea89e49074e48270dc5e1b9511a0f9" }, - "mini.starter": { "branch": "main", "commit": "ce222a5b6de50a9963c1eb62aa16ec6d5efca7ee" }, + "mini.align": { "branch": "main", "commit": "68a8d3205f0e7ce1bded057f4a851f42ef8fc584" }, + "mini.starter": { "branch": "main", "commit": "3c6ed3caaadef35291e98f0701038254ee1e78b0" }, "neo-tree.nvim": { "branch": "main", "commit": "8c75e8a2949cd6cd35525799200a8d34471ee9eb" }, "neotest": { "branch": "master", "commit": "f30bab1faef13d47f3905e065215c96a42d075ad" }, "neotest-go": { "branch": "main", "commit": "92950ad7be2ca02a41abca5c6600ff6ffaf5b5d6" }, "neotest-python": { "branch": "master", "commit": "2e83d2bc00acbcc1fd529dbf0a0e677cabfe6b50" }, "neovim-project": { "branch": "main", "commit": "8587bda684e15db00cf073663ff28401243a97e3" }, "neovim-session-manager": { "branch": "master", "commit": "29f80e9c6f3620b81908e287b3d1ed79c2290dd5" }, - "noice.nvim": { "branch": "main", "commit": "a9fa1a2ace124fcb752e356b3c52e962c3dcb8b8" }, - "none-ls.nvim": { "branch": "main", "commit": "8691504118b252d64fc5023a104aedd100ab754a" }, + "noice.nvim": { "branch": "main", "commit": "f65b6b7ab87796f93ea8f8a92d5a64dc53d912d1" }, + "none-ls.nvim": { "branch": "main", "commit": "cc0a3c45047e3daf85d07c1571d65476cfce6480" }, "nui.nvim": { "branch": "main", "commit": "322978c734866996274467de084a95e4f9b5e0b1" }, "nvim-autopairs": { "branch": "master", "commit": "c15de7e7981f1111642e7e53799e1211d4606cb9" }, "nvim-cmp": { "branch": "main", "commit": "a110e12d0b58eefcf5b771f533fc2cf3050680ac" }, @@ -48,9 +48,9 @@ "nvim-dap-python": { "branch": "master", "commit": "ae0225d0d4a46e18e6057ab3701ef87bbbd6aaad" }, "nvim-dap-ui": { "branch": "master", "commit": "f7d75cca202b52a60c520ec7b1ec3414d6e77b0f" }, "nvim-dap-virtual-text": { "branch": "master", "commit": "d7c695ea39542f6da94ee4d66176f5d660ab0a77" }, - "nvim-lspconfig": { "branch": "master", "commit": "4d38bece98300e3e5cd24a9aa0d0ebfea4951c16" }, + "nvim-lspconfig": { "branch": "master", "commit": "37f362ef42d1a604d332e8d3d7d47593852b4313" }, "nvim-nio": { "branch": "master", "commit": "7969e0a8ffabdf210edd7978ec954a47a737bbcc" }, - "nvim-treesitter": { "branch": "master", "commit": "26171d8f105d97746371d1b6c07c8d88bf13fec2" }, + "nvim-treesitter": { "branch": "master", "commit": "8dd40c7609c04d7bad7eb21d71f78c3fa4dc1c2c" }, "nvim-ts-context-commentstring": { "branch": "main", "commit": "cb064386e667def1d241317deed9fd1b38f0dc2e" }, "nvim-ufo": { "branch": "main", "commit": "aa2e676af592b4e99c105d80d6eafd1afc215d99" }, "nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" }, @@ -61,8 +61,8 @@ "telescope-fzf-native.nvim": { "branch": "main", "commit": "9ef21b2e6bb6ebeaf349a0781745549bbb870d27" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "f12b15e1b3a33524eb06a1ae7bc852fb1fd92197" }, - "tokyonight.nvim": { "branch": "main", "commit": "d68b8003a581c2e51a7bea465d1898fb7f7c8966" }, - "trouble.nvim": { "branch": "main", "commit": "88a40f1cc3af846b520ae167f0177b5faa148c86" }, + "tokyonight.nvim": { "branch": "main", "commit": "81c867c5f638597a82c82094dcb90ed42444dabc" }, + "trouble.nvim": { "branch": "main", "commit": "e0b35a273df58b03612255783cf475a782ede7e0" }, "typescript-tools.nvim": { "branch": "master", "commit": "c43d9580c3ff5999a1eabca849f807ab33787ea7" }, "venv-selector.nvim": { "branch": "regexp", "commit": "d946b1e86212f38ff9c42e3b622a8178bbc93461" }, "vim-bbye": { "branch": "master", "commit": "25ef93ac5a87526111f43e5110675032dbcacf56" }, diff --git a/.config/nvim/lua/core/lazy.lua b/.config/nvim/lua/core/lazy.lua index 40777de..55de354 100644 --- a/.config/nvim/lua/core/lazy.lua +++ b/.config/nvim/lua/core/lazy.lua @@ -19,34 +19,6 @@ local lazy_opts = { }, } -local uv = vim.loop -local function readFile(path) - local fd = uv.fs_open(path, "r", 438) - if fd == nil then - return nil - end - local stat = uv.fs_fstat(fd) - if fd == nil then - return nil - end - local data = uv.fs_read(fd, stat.size, 0) - if data == nil then - return nil - end - assert(uv.fs_close(fd)) - - return data -end - -local projects = function() - local data = readFile(os.getenv("HOME") .. "/.config/nvim/neovim-projects.json") - if data then - return vim.json.decode(data) - else - return {} - end -end - require("lazy").setup({ -- Colorschemes { @@ -111,7 +83,7 @@ require("lazy").setup({ { "nvim-lua/plenary.nvim", lazy = true }, { "echasnovski/mini.starter", lazy = "VimEnter", version = "*" }, { "windwp/nvim-autopairs" }, - { "numToStr/Comment.nvim", version = "v0.*" }, + { "numToStr/Comment.nvim" }, { "JoosepAlviste/nvim-ts-context-commentstring" }, { "nvim-tree/nvim-web-devicons", lazy = true }, { "akinsho/bufferline.nvim", event = "VeryLazy", version = "v4.*" }, @@ -130,14 +102,6 @@ require("lazy").setup({ { "mg979/vim-visual-multi" }, { "coffebar/neovim-project", - opts = { - projects = projects(), - last_session_on_startup = false, - filetype_autocmd_timeout = 0, - }, - init = function() - vim.opt.sessionoptions:append("globals") - end, dependencies = { { "Shatur/neovim-session-manager" }, }, @@ -154,7 +118,6 @@ require("lazy").setup({ { "tenxsoydev/karen-yank.nvim", event = "VeryLazy", config = true }, { "ggandor/leap.nvim", - version = "*", config = function() require("leap").add_default_mappings() vim.api.nvim_set_hl(0, "LeapBackdrop", { link = "Comment" }) @@ -162,7 +125,6 @@ require("lazy").setup({ }, { "knubie/vim-kitty-navigator", - version = "*", build = "cp ./*.py ~/.config/kitty/", }, { diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 0364ca2..60de393 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -24,3 +24,4 @@ require("plugins.ufo") require("plugins.bufferline") require("plugins.lualine") require("plugins.grug-far") +require("plugins.neovim-project") diff --git a/.config/nvim/lua/plugins/neovim-project.lua b/.config/nvim/lua/plugins/neovim-project.lua new file mode 100644 index 0000000..b6eeecb --- /dev/null +++ b/.config/nvim/lua/plugins/neovim-project.lua @@ -0,0 +1,19 @@ +local projects = function() + local data = require("util.files").read(os.getenv("HOME") .. "/.config/nvim/neovim-projects.json") + if data then + return vim.json.decode(data) + else + return {} + end +end + +require("neovim-project").setup({ + projects = projects(), + last_session_on_startup = false, + dashboard_mode = true, + filetype_autocmd_timeout = 0, + autosave_ignore_filetypes = { + "neo-tree", + "trouble", + }, +}) diff --git a/.config/nvim/lua/util/files.lua b/.config/nvim/lua/util/files.lua new file mode 100644 index 0000000..54cf340 --- /dev/null +++ b/.config/nvim/lua/util/files.lua @@ -0,0 +1,10 @@ +local M = {} + +M.read = function(file) + local fd = assert(io.open(file, "r")) + local data = fd:read("*a") + fd:close() + return data +end + +return M