From 3a149e733abde4a95a33500cdfe9b73bb0f6e7c0 Mon Sep 17 00:00:00 2001 From: Konstantinos Despoinidis Date: Sun, 24 Dec 2023 19:26:08 +0200 Subject: [PATCH] added ruby --- doc/project-starter.txt | 1 + lua/project-starter/builders.lua | 13 +++++++++++++ lua/project-starter/commands.lua | 4 ++++ lua/project-starter/init.lua | 9 +++++++-- lua/project-starter/utils.lua | 22 ++++++++++++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/doc/project-starter.txt b/doc/project-starter.txt index b318128..a7d48e6 100644 --- a/doc/project-starter.txt +++ b/doc/project-starter.txt @@ -28,5 +28,6 @@ 3. Java Swing 4. Neovim Plugin 5. Python + 6. Ruby vim:tw=78:ts=8:ft=help:norl: diff --git a/lua/project-starter/builders.lua b/lua/project-starter/builders.lua index ccfd5f2..6d9dae6 100644 --- a/lua/project-starter/builders.lua +++ b/lua/project-starter/builders.lua @@ -69,6 +69,19 @@ return { utils.change_nvim_directory(path .. name) + return path .. name + end, + + ["ruby"] = function(name) + name = name or vim.fn.input("Name: ") + local path = paths["ruby"] + + if not utils.handle_invalid_path(path) then return nil end + + run_command.ruby(path, name) + + utils.change_nvim_directory(path .. name) + return path .. name end } diff --git a/lua/project-starter/commands.lua b/lua/project-starter/commands.lua index 7aba044..a56dfaf 100644 --- a/lua/project-starter/commands.lua +++ b/lua/project-starter/commands.lua @@ -22,4 +22,8 @@ return { python = function (path, name) vim.cmd(":silent !cd " .. path .. " && " .. "git clone https://github.com/KDesp73/python-starter.git " .. name) end, + + ruby = function (path, name) + vim.cmd(":silent !cd " .. path .. " && " .. "bundle gem " .. name) + end } diff --git a/lua/project-starter/init.lua b/lua/project-starter/init.lua index de8c8ee..3cf6d80 100644 --- a/lua/project-starter/init.lua +++ b/lua/project-starter/init.lua @@ -26,6 +26,9 @@ M.setup = function (opts) if opts.default_paths.python then paths.python = opts.default_paths.python end + if opts.default_paths.ruby then + paths.ruby = opts.default_paths.ruby + end end if opts.cd ~= nil then @@ -53,8 +56,10 @@ vim.api.nvim_create_user_command( local arguments = {} for word in args.args:gmatch("%w+") do table.insert(arguments, word) end - if arguments == {} then - print("At least one argument is needed (cpp, java, swing, nvim_plugin, python)") + -- P(args) + + if #arguments == 0 then + print("At least one argument is needed (" .. utils.get_implemented_languages() .. ")") return nil end diff --git a/lua/project-starter/utils.lua b/lua/project-starter/utils.lua index 64ecf97..65862ea 100644 --- a/lua/project-starter/utils.lua +++ b/lua/project-starter/utils.lua @@ -51,4 +51,26 @@ utils.handle_invalid_path = function(path) return true end +utils.get_implemented_languages = function () + local keyset = {} + + for k, v in pairs(require("project-starter.builders")) do + table.insert(keyset, k) + end + + local str = "" + + for i = 1, #keyset do + str = str .. keyset[i] .. ", " + end + + -- Check if the string is not empty before attempting to remove the last two characters + if #str > 0 then + return str:sub(1, -3) + else + return str + end +end + + return utils