Skip to content

Commit

Permalink
added ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
KDesp73 committed Dec 24, 2023
1 parent 2000eb6 commit 3a149e7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/project-starter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
3. Java Swing
4. Neovim Plugin
5. Python
6. Ruby

vim:tw=78:ts=8:ft=help:norl:
13 changes: 13 additions & 0 deletions lua/project-starter/builders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions lua/project-starter/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 7 additions & 2 deletions lua/project-starter/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions lua/project-starter/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3a149e7

Please sign in to comment.