From 637bdfc93bb1339b4c8c37d17a69ed4475c2625e Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Thu, 11 May 2023 17:30:35 +0300 Subject: [PATCH] add MIT license snippet --- lua/config/cmp.lua | 4 +-- lua/config/luasnip.lua | 55 ++++++++++++++++++++++++++++++++++++++++++ lua/plugins.lua | 2 +- lua/utils/capture.lua | 10 ++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 lua/config/luasnip.lua create mode 100644 lua/utils/capture.lua diff --git a/lua/config/cmp.lua b/lua/config/cmp.lua index 400a46b..1cccff9 100644 --- a/lua/config/cmp.lua +++ b/lua/config/cmp.lua @@ -53,9 +53,9 @@ cmp.setup{ { name = 'nvim_lua' }, { name = 'nvim_lsp', max_item_count = 20 }, + { name = 'luasnip' }, { name = 'cmp_tabnine' }, { name = 'path' }, - { name = 'luasnip' }, { name = 'buffer', max_item_count = 10, keyword_length = 5 }, }, formatting = { @@ -92,5 +92,3 @@ cmp.setup.cmdline('/', { -- { name = 'cmdline' } -- }) -- }) - - diff --git a/lua/config/luasnip.lua b/lua/config/luasnip.lua new file mode 100644 index 0000000..1e1e3f6 --- /dev/null +++ b/lua/config/luasnip.lua @@ -0,0 +1,55 @@ +local ls = require("luasnip") +local capture = require("utils.capture") +local s = ls.snippet +local sn = ls.snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local choice = ls.choice_node +local d = ls.dynamic_node + +local function getCurrentYear() + return os.date("%Y") +end + +local function getGitUsername() + local stdout = capture("git config user.name") + if stdout == "" then + return nil + end + return stdout +end + +ls.add_snippets("all", { + s("MIT", { + t({"The MIT License (MIT)", "Copyright © "}), + f(getCurrentYear, {}), + t(" "), + d(1, function() + return sn(nil, { + i(1, getGitUsername() or "") + }) + end, {}), + t{ + "", + "", + "Permission is hereby granted, free of charge, to any person obtaining a copy of", + "this software and associated documentation files (the “Software”), to deal in", + "the Software without restriction, including without limitation the rights to", + "use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies", + "of the Software, and to permit persons to whom the Software is furnished to do", + "so, subject to the following conditions:", + "", + "The above copyright notice and this permission notice shall be included in all", + "copies or substantial portions of the Software.", + "", + "THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE", + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER", + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,", + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE", + "SOFTWARE.", + } + }) +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index 58bcaa4..9f05700 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -128,7 +128,7 @@ local function usePlugins(use, use_rocks) use 'tpope/vim-eunuch' -- Snippets - use 'L3MON4D3/LuaSnip' + use { 'L3MON4D3/LuaSnip', after = 'nvim-cmp', config = [[require 'config.luasnip']] } -- Movement utilities use 'tpope/vim-unimpaired' diff --git a/lua/utils/capture.lua b/lua/utils/capture.lua new file mode 100644 index 0000000..35f3dfb --- /dev/null +++ b/lua/utils/capture.lua @@ -0,0 +1,10 @@ +return function (cmd, raw) + local f = assert(io.popen(cmd, 'r')) + local s = assert(f:read('*a')) + f:close() + if raw then return s end + s = string.gsub(s, '^%s+', '') + s = string.gsub(s, '%s+$', '') + s = string.gsub(s, '[\n\r]+', ' ') + return s +end