From 81dacf09a375dc39a371cc01622925e77166b5dd Mon Sep 17 00:00:00 2001 From: Traap Date: Wed, 15 Feb 2023 14:25:35 -0800 Subject: [PATCH 1/3] Bootstrap neovim. 1. dev function completely removes a prior Neovim installation and reset the default Neovim (init.lua) to reference this directory. 2. theprimeagen/bootstrap is added to automatically install packer when necessary. 3. each plugin uses pcall to prevent its use prior to loading. 4. theprimeagen/init directly references bootstrap and packer. --- README.md | 8 +++ after/plugin/cloak.lua | 42 +++++++------- after/plugin/colors.lua | 7 ++- after/plugin/harpoon.lua | 9 +-- after/plugin/lsp.lua | 8 ++- after/plugin/refactoring.lua | 8 +-- after/plugin/telescope.lua | 4 +- after/plugin/treesitter.lua | 5 +- dev | 9 ++- lua/theprimeagen/bootstrap.lua | 18 ++++++ lua/theprimeagen/init.lua | 4 +- lua/theprimeagen/packer.lua | 102 ++++++++++++++++++++++----------- 12 files changed, 151 insertions(+), 73 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 after/plugin/cloak.lua mode change 100644 => 100755 after/plugin/colors.lua mode change 100644 => 100755 after/plugin/harpoon.lua mode change 100644 => 100755 after/plugin/lsp.lua mode change 100644 => 100755 after/plugin/refactoring.lua mode change 100644 => 100755 after/plugin/telescope.lua mode change 100644 => 100755 after/plugin/treesitter.lua create mode 100755 lua/theprimeagen/bootstrap.lua mode change 100644 => 100755 lua/theprimeagen/init.lua mode change 100644 => 100755 lua/theprimeagen/packer.lua diff --git a/README.md b/README.md old mode 100644 new mode 100755 index aa3823b8..9d2ffb3f --- a/README.md +++ b/README.md @@ -15,4 +15,12 @@ about though i would just suggest `git log -S`). * [4a96e645](https://github.com/ThePrimeagen/init.lua/commit/4a96e6457b0a0241ca7361ce62177aa6b9a33a38) fugitive mappings for push and pull * [a3bad06a](https://github.com/ThePrimeagen/init.lua/commit/a3bad06a4681c322538d609aa1c0bd18880f77c6) disabled eslint. driving me crazy +### Extra credit (only for the fearless!!) +### Automatically bootstrap my configuration with two steps. +1. ./dev +2. nvim +#### 100% Pure Coconut Oil. +The two steps above will completely remove your Neovim endowment and then reload +it. The first Neovim run loads all packages, and the second run causes +Treesitter to install language highlighting. diff --git a/after/plugin/cloak.lua b/after/plugin/cloak.lua old mode 100644 new mode 100755 index 1eaf7d0f..58b2c200 --- a/after/plugin/cloak.lua +++ b/after/plugin/cloak.lua @@ -1,22 +1,24 @@ -require("cloak").setup({ - enabled = true, - cloak_character = "*", - -- The applied highlight group (colors) on the cloaking, see `:h highlight`. - highlight_group = "Comment", - patterns = { - { - -- Match any file starting with ".env". - -- This can be a table to match multiple file patterns. - file_pattern = { - ".env*", - "wrangler.toml", - ".dev.vars", - }, - -- Match an equals sign and any character after it. - -- This can also be a table of patterns to cloak, - -- example: cloak_pattern = { ":.+", "-.+" } for yaml files. - cloak_pattern = "=.+" +local ok, plugin = pcall(require, 'cloak') +if not ok then return end + +plugin.setup({ + enabled = true, + cloak_character = "*", + -- The applied highlight group (colors) on the cloaking, see `:h highlight`. + highlight_group = "Comment", + patterns = { + { + -- Match any file starting with ".env". + -- This can be a table to match multiple file patterns. + file_pattern = { + ".env*", + "wrangler.toml", + ".dev.vars", + }, + -- Match an equals sign and any character after it. + -- This can also be a table of patterns to cloak, + -- example: cloak_pattern = { ":.+", "-.+" } for yaml files. + cloak_pattern = "=.+" + }, }, - }, }) - diff --git a/after/plugin/colors.lua b/after/plugin/colors.lua old mode 100644 new mode 100755 index fe97b1bb..8041a822 --- a/after/plugin/colors.lua +++ b/after/plugin/colors.lua @@ -1,8 +1,11 @@ -require('rose-pine').setup({ +local ok, plugin = pcall(require, 'rose-pine') +if not ok then return end + +plugin.setup({ disable_background = true }) -function ColorMyPencils(color) +function ColorMyPencils(color) color = color or "rose-pine" vim.cmd.colorscheme(color) diff --git a/after/plugin/harpoon.lua b/after/plugin/harpoon.lua old mode 100644 new mode 100755 index 4a6ba871..a7a5d321 --- a/after/plugin/harpoon.lua +++ b/after/plugin/harpoon.lua @@ -1,5 +1,8 @@ -local mark = require("harpoon.mark") -local ui = require("harpoon.ui") +local mok, mark = pcall(require, 'harpoon.mark') +if not mok then return end + +local uok, ui = pcall(require, 'harpoon.ui') +if not uok then return end vim.keymap.set("n", "a", mark.add_file) vim.keymap.set("n", "", ui.toggle_quick_menu) @@ -8,5 +11,3 @@ vim.keymap.set("n", "", function() ui.nav_file(1) end) vim.keymap.set("n", "", function() ui.nav_file(2) end) vim.keymap.set("n", "", function() ui.nav_file(3) end) vim.keymap.set("n", "", function() ui.nav_file(4) end) - - diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua old mode 100644 new mode 100755 index ca85cbec..52605223 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -1,10 +1,15 @@ -local lsp = require("lsp-zero") +local lok, lsp = pcall(require, 'lsp-zero') +if not lok then return end + +local cok, cmp = pcall(require, 'cmp') +if not cok then return end lsp.preset("recommended") lsp.ensure_installed({ 'tsserver', 'rust_analyzer', + 'lua_ls', }) -- Fix Undefined global 'vim' @@ -19,7 +24,6 @@ lsp.configure('lua-language-server', { }) -local cmp = require('cmp') local cmp_select = {behavior = cmp.SelectBehavior.Select} local cmp_mappings = lsp.defaults.cmp_mappings({ [''] = cmp.mapping.select_prev_item(cmp_select), diff --git a/after/plugin/refactoring.lua b/after/plugin/refactoring.lua old mode 100644 new mode 100755 index 2f9f70c1..c35d59fb --- a/after/plugin/refactoring.lua +++ b/after/plugin/refactoring.lua @@ -1,5 +1,5 @@ -require('refactoring').setup({}) - -vim.api.nvim_set_keymap("v", "ri", [[ lua require('refactoring').refactor('Inline Variable')]], {noremap = true, silent = true, expr = false}) - +local ok, plugin = pcall(require, 'refactoring') +if not ok then return end +plugin.setup({}) +vim.api.nvim_set_keymap("v", "ri", [[ lua plugin.refactor('Inline Variable')]], {noremap = true, silent = true, expr = false}) diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua old mode 100644 new mode 100755 index 29f5a62f..3826bfc1 --- a/after/plugin/telescope.lua +++ b/after/plugin/telescope.lua @@ -1,4 +1,6 @@ -local builtin = require('telescope.builtin') +local ok, builtin = pcall(require, 'telescope.builtin') +if not ok then return end + vim.keymap.set('n', 'pf', builtin.find_files, {}) vim.keymap.set('n', '', builtin.git_files, {}) vim.keymap.set('n', 'ps', function() diff --git a/after/plugin/treesitter.lua b/after/plugin/treesitter.lua old mode 100644 new mode 100755 index 9d5d923f..0a82dc3e --- a/after/plugin/treesitter.lua +++ b/after/plugin/treesitter.lua @@ -1,4 +1,7 @@ -require'nvim-treesitter.configs'.setup { +local ok, plugin = pcall(require, 'nvim-treesitter.config') +if not ok then return end + +plugin.setup { -- A list of parser names, or "all" ensure_installed = { "help", "javascript", "typescript", "c", "lua", "rust" }, diff --git a/dev b/dev index 6f51fbc7..6b342fb3 100755 --- a/dev +++ b/dev @@ -1,5 +1,8 @@ #!/usr/bin/env bash -rm -rf ~/.config/nvim -ln -s $(pwd) ~/.config/nvim - +rm -rfv ~/.cache/nvim +rm -rfv ~/.config/nvim +rm -rfv ~/.local/share/nvim +rm -rfv ~/.local/state/nvim +rm -rfv $(pwd)/plugin +ln -fsv $(pwd) ~/.config/nvim diff --git a/lua/theprimeagen/bootstrap.lua b/lua/theprimeagen/bootstrap.lua new file mode 100755 index 00000000..850be939 --- /dev/null +++ b/lua/theprimeagen/bootstrap.lua @@ -0,0 +1,18 @@ +-- Auto install packer.nvim if when needed. + +-- Set installation path and clone url. +local path = vim.fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' +local url = 'https://github.com/wbthomason/packer.nvim' + +-- Clone packer if necessary. +if vim.fn.empty(vim.fn.glob(path)) > 0 then + vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#1e222a" }) + print('Installing packer.') + vim.fn.system({'git', 'clone', '--depth', '1', url, path}) + vim.g.nvim_bootstrapped = 1 + + -- Add packer. + vim.cmd [[packadd packer.nvim]] +else + vim.g.nvim_bootstrapped = 0 +end diff --git a/lua/theprimeagen/init.lua b/lua/theprimeagen/init.lua old mode 100644 new mode 100755 index 8db3ffac..395fe706 --- a/lua/theprimeagen/init.lua +++ b/lua/theprimeagen/init.lua @@ -1,8 +1,10 @@ +require("theprimeagen.bootstrap") +require("theprimeagen.packer") require("theprimeagen.set") require("theprimeagen.remap") -- DO NOT INCLUDE THIS -vim.opt.rtp:append("~/personal/streamer-tools") +-- vim.opt.rtp:append("~/personal/streamer-tools") -- DO NOT INCLUDE THIS local augroup = vim.api.nvim_create_augroup diff --git a/lua/theprimeagen/packer.lua b/lua/theprimeagen/packer.lua old mode 100644 new mode 100755 index cd886f38..03630dc2 --- a/lua/theprimeagen/packer.lua +++ b/lua/theprimeagen/packer.lua @@ -1,24 +1,37 @@ --- This file can be loaded by calling `lua require('plugins')` from your init.vim +-- Use protected call so we don't error on first use. +local packer_ok, packer = pcall(require, 'packer') +if not packer_ok then return end --- Only required if you have packer configured as `opt` -vim.cmd.packadd('packer.nvim') +-- Have packer use a popup window +packer.init { + display = { + open_fn = function() + return require("packer.util").float { border = "rounded" } + end, + }, + max_jobs = 50, +} + +-- Packer startup function definitions. +-- +return packer.startup(function(use) -return require('packer').startup(function(use) -- Packer can manage itself use 'wbthomason/packer.nvim' use { - 'nvim-telescope/telescope.nvim', tag = '0.1.0', - -- or , branch = '0.1.x', - requires = { {'nvim-lua/plenary.nvim'} } + 'nvim-telescope/telescope.nvim', tag = '0.1.0', + -- or , branch = '0.1.x', + requires = { {'nvim-lua/plenary.nvim'} } } use({ - 'rose-pine/neovim', - as = 'rose-pine', - config = function() - vim.cmd('colorscheme rose-pine') - end + 'rose-pine/neovim', + as = 'rose-pine', + config = function() + require("rose-pine").setup() + vim.cmd('colorscheme rose-pine') + end }) use({ @@ -34,35 +47,49 @@ return require('packer').startup(function(use) }) - use({"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"}) - use("nvim-treesitter/playground") + use{ + "nvim-treesitter/nvim-treesitter", + run = function() + pcall(require("nvim-treesitter.install").update{ with_sync = true}) + end, + } + + use { + "nvim-treesitter/playground", + after = 'nvim-treesitter', + } + + use { + "nvim-treesitter/nvim-treesitter-context", + after = 'nvim-treesitter', + } + use("theprimeagen/harpoon") use("theprimeagen/refactoring.nvim") use("mbbill/undotree") use("tpope/vim-fugitive") - use("nvim-treesitter/nvim-treesitter-context"); use { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v1.x', - requires = { - -- LSP Support - {'neovim/nvim-lspconfig'}, - {'williamboman/mason.nvim'}, - {'williamboman/mason-lspconfig.nvim'}, - - -- Autocompletion - {'hrsh7th/nvim-cmp'}, - {'hrsh7th/cmp-buffer'}, - {'hrsh7th/cmp-path'}, - {'saadparwaiz1/cmp_luasnip'}, - {'hrsh7th/cmp-nvim-lsp'}, - {'hrsh7th/cmp-nvim-lua'}, - - -- Snippets - {'L3MON4D3/LuaSnip'}, - {'rafamadriz/friendly-snippets'}, - } + 'VonHeikemen/lsp-zero.nvim', + branch = 'v1.x', + requires = { + -- LSP Support + {'neovim/nvim-lspconfig'}, + {'williamboman/mason.nvim'}, + {'williamboman/mason-lspconfig.nvim'}, + + -- Autocompletion + {'hrsh7th/nvim-cmp'}, + {'hrsh7th/cmp-buffer'}, + {'hrsh7th/cmp-path'}, + {'saadparwaiz1/cmp_luasnip'}, + {'hrsh7th/cmp-nvim-lsp'}, + {'hrsh7th/cmp-nvim-lua'}, + + -- Snippets + {'L3MON4D3/LuaSnip'}, + {'rafamadriz/friendly-snippets'}, + } } use("folke/zen-mode.nvim") @@ -70,5 +97,10 @@ return require('packer').startup(function(use) use("eandrju/cellular-automaton.nvim") use("laytan/cloak.nvim") + -- Auto compile and install plugins when packer is bootstrapped. + if vim.g.nvim_bootstrapped == 1 then + packer.sync() + end + end) From ed1a483a66e0f81e33d76805d369a173678a55e5 Mon Sep 17 00:00:00 2001 From: Traap Date: Wed, 15 Feb 2023 14:43:56 -0800 Subject: [PATCH 2/3] Add function file_exists. --- lua/theprimeagen/init.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lua/theprimeagen/init.lua b/lua/theprimeagen/init.lua index 395fe706..08e62bde 100755 --- a/lua/theprimeagen/init.lua +++ b/lua/theprimeagen/init.lua @@ -1,11 +1,19 @@ +-- https://www.grepper.com/answers/120776/how+to+check+if+file+exists+lua +local function file_exists(name) + local f=io.open(name,'r') + if f ~= nil then io.close() return true else return false end +end + +-- required modules. require("theprimeagen.bootstrap") require("theprimeagen.packer") require("theprimeagen.set") require("theprimeagen.remap") --- DO NOT INCLUDE THIS --- vim.opt.rtp:append("~/personal/streamer-tools") --- DO NOT INCLUDE THIS +-- Don't use my streaming tools. +if file_exists("~/personal/streamer-tools") then + vim.opt.rtp:append("~/personal/streamer-tools") +end local augroup = vim.api.nvim_create_augroup local ThePrimeagenGroup = augroup('ThePrimeagen', {}) From f0708d296a76ee23b9789b240919f99777157140 Mon Sep 17 00:00:00 2001 From: Traap Date: Tue, 21 Feb 2023 21:53:54 -0800 Subject: [PATCH 3/3] Add YouTube TODO Markers. --- lua/theprimeagen/bootstrap.lua | 2 +- lua/theprimeagen/init.lua | 7 +++++-- lua/theprimeagen/packer.lua | 6 +++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lua/theprimeagen/bootstrap.lua b/lua/theprimeagen/bootstrap.lua index 850be939..378ae949 100755 --- a/lua/theprimeagen/bootstrap.lua +++ b/lua/theprimeagen/bootstrap.lua @@ -4,7 +4,7 @@ local path = vim.fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' local url = 'https://github.com/wbthomason/packer.nvim' --- Clone packer if necessary. +-- TODO: Clone packer if necessary. if vim.fn.empty(vim.fn.glob(path)) > 0 then vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#1e222a" }) print('Installing packer.') diff --git a/lua/theprimeagen/init.lua b/lua/theprimeagen/init.lua index 08e62bde..c9e9ca6d 100755 --- a/lua/theprimeagen/init.lua +++ b/lua/theprimeagen/init.lua @@ -1,16 +1,19 @@ +-- TODO: Add file exists function. -- https://www.grepper.com/answers/120776/how+to+check+if+file+exists+lua local function file_exists(name) local f=io.open(name,'r') if f ~= nil then io.close() return true else return false end end --- required modules. +-- TODO: Bootstrap when necessary. require("theprimeagen.bootstrap") + +-- required modules. require("theprimeagen.packer") require("theprimeagen.set") require("theprimeagen.remap") --- Don't use my streaming tools. +-- TODO: Don't use my streaming tools. if file_exists("~/personal/streamer-tools") then vim.opt.rtp:append("~/personal/streamer-tools") end diff --git a/lua/theprimeagen/packer.lua b/lua/theprimeagen/packer.lua index 03630dc2..a8e79b3c 100755 --- a/lua/theprimeagen/packer.lua +++ b/lua/theprimeagen/packer.lua @@ -1,8 +1,8 @@ --- Use protected call so we don't error on first use. +-- TODO: Use protected call so we don't error on first use. local packer_ok, packer = pcall(require, 'packer') if not packer_ok then return end --- Have packer use a popup window +-- TODO: Have packer use a popup window packer.init { display = { open_fn = function() @@ -97,7 +97,7 @@ return packer.startup(function(use) use("eandrju/cellular-automaton.nvim") use("laytan/cloak.nvim") - -- Auto compile and install plugins when packer is bootstrapped. + -- TODO: Auto compile and install plugins when packer is bootstrapped. if vim.g.nvim_bootstrapped == 1 then packer.sync() end