From e901a69f2844e261055b7753019dae80f6ba1a46 Mon Sep 17 00:00:00 2001 From: leafee98 Date: Fri, 21 Jul 2023 16:29:53 +0800 Subject: [PATCH] drop _full_feature and use custom.lua * use a global table for custom config * add config for proxy --- .gitignore | 2 +- README.md | 7 +++++-- init.lua | 16 ++++++++++++---- lua/plugins/10-editor.lua | 8 ++++---- lua/plugins/20-git.lua | 2 +- lua/plugins/20-treesitter.lua | 8 ++++++-- lua/plugins/50-lsp.lua | 2 +- 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index ef5a10d..9d557fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /lazy-lock.json -/_full_feature +/custom.lua diff --git a/README.md b/README.md index 9146be5..26acac8 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,11 @@ git clone ~/.config/nvim By default, this config will only include a few plugins, which suit for mataining other than editing frequently. -If you want to use the full feature this config provided, create a file named `_full_feature` under the root of this repo (usually `~/.config/nvim`. +A custom config (`custom.lua`) file placed aside with `init.lua` is optional, it's content like below. ``` -touch ~/.config/nvim/_full_feature +return { + full_feature = true, # enable all configured plugins + proxy_url = "http://localhost:8888", # setup proxy for some plugins (like treesitter) +} ``` diff --git a/init.lua b/init.lua index 3b72e45..93b75e4 100644 --- a/init.lua +++ b/init.lua @@ -26,11 +26,19 @@ vim.keymap.set("n", "", "bnext", { silent = true }) vim.g.mapleader = " " vim.g.maplocalleader = " " -function file_exists(name) - local f=io.open(name,"r") - if f~=nil then io.close(f) return true else return false end +-- Load custom config +custom = { + full_feature = false, + proxy_url = "", +} + +local custom_config_path = vim.fn.stdpath("config") .. "/custom.lua" +local ok, t = pcall(dofile, custom_config_path) +if ok then + for k, v in pairs(t) do + custom[k] = v + end end -full_feature = file_exists(vim.fn.stdpath("config") .. "/_full_feature") -- Use lazy.nvim as plugin manager, and load plugin's config local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" diff --git a/lua/plugins/10-editor.lua b/lua/plugins/10-editor.lua index 52d78a5..5bbf49c 100644 --- a/lua/plugins/10-editor.lua +++ b/lua/plugins/10-editor.lua @@ -24,13 +24,13 @@ return { }, { "karb94/neoscroll.nvim", - enabled = full_feature, + enabled = custom.full_feature, main = "neoscroll", opts = { }, }, { "akinsho/bufferline.nvim", - enabled = full_feature, + enabled = custom.full_feature, main = "bufferline", opts = { options = { @@ -54,7 +54,7 @@ return { }, { "nvim-lualine/lualine.nvim", - enabled = full_feature, + enabled = custom.full_feature, dependencies = { "nvim-tree/nvim-web-devicons" }, @@ -66,7 +66,7 @@ return { }, { "nvim-tree/nvim-tree.lua", - enabled = full_feature, + enabled = custom.full_feature, dependencies = { "nvim-tree/nvim-web-devicons" }, diff --git a/lua/plugins/20-git.lua b/lua/plugins/20-git.lua index a41628d..28e0b55 100644 --- a/lua/plugins/20-git.lua +++ b/lua/plugins/20-git.lua @@ -1,7 +1,7 @@ return { "lewis6991/gitsigns.nvim", main = "gitsigns", - enabled = full_feature, + enabled = custom.full_feature, opts = { on_attach = function(bufnr) local gs = package.loaded.gitsigns diff --git a/lua/plugins/20-treesitter.lua b/lua/plugins/20-treesitter.lua index cb86db3..e2354d7 100644 --- a/lua/plugins/20-treesitter.lua +++ b/lua/plugins/20-treesitter.lua @@ -44,7 +44,7 @@ local basic_ensure = { "yaml", } -if full_feature then +if custom.full_feature then ensure = full_ensure else ensure = basic_ensure @@ -63,6 +63,10 @@ return { }, config = function (this, opts) require(this.name .. ".configs").setup(opts); - require(this.name .. ".install").prefer_git = true; + if custom.proxy_url ~= "" then + require(this.name .. ".install").command_extra_args = { + curl = { "--proxy", custom.proxy_url } + } + end end } diff --git a/lua/plugins/50-lsp.lua b/lua/plugins/50-lsp.lua index 098efa9..649f4f3 100644 --- a/lua/plugins/50-lsp.lua +++ b/lua/plugins/50-lsp.lua @@ -39,7 +39,7 @@ end return { { "neovim/nvim-lspconfig", - enabled = full_feature, + enabled = custom.full_feature, dependencies = { "hrsh7th/nvim-cmp", "hrsh7th/cmp-nvim-lsp",