aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorGiuseppe Gadola <giusgadola@gmail.com>2023-02-13 11:53:59 +0100
committerGiuseppe Gadola <giusgadola@gmail.com>2023-02-13 11:53:59 +0100
commit4e27e123ae3283cf5a08339dd4a67bc28c2bfba7 (patch)
tree94fe9de637712f114de4e88a734057f9e0bef545 /lua
parentchore: deleted .github/workflows directory (diff)
feat(options): added the random options for the PetsNew command
Diffstat (limited to 'lua')
-rw-r--r--lua/pets.lua1
-rw-r--r--lua/pets/commands.lua10
2 files changed, 9 insertions, 2 deletions
diff --git a/lua/pets.lua b/lua/pets.lua
index fd71b2b..7e4d4c2 100644
--- a/lua/pets.lua
+++ b/lua/pets.lua
@@ -6,6 +6,7 @@ M.options = {
speed_multiplier = 1,
default_pet = "cat",
default_style = "brown",
+ random = true,
}
M.pets = {}
diff --git a/lua/pets/commands.lua b/lua/pets/commands.lua
index 3274aba..ab64fdb 100644
--- a/lua/pets/commands.lua
+++ b/lua/pets/commands.lua
@@ -1,13 +1,19 @@
local pets = require("pets")
+local wd = debug.getinfo(1).source:sub(2):match("(.*nvim/)") .. "media/"
vim.api.nvim_create_user_command("PetsNew", function(input)
- pets.create_pet(input.args, pets.options.default_pet, pets.options.default_style)
+ --TODO: validate style and type options
+ local pet, style = pets.options.default_pet, pets.options.default_style
+ if pets.options.random then
+ local styles = require("pets.utils").listdir(wd .. "cat")
+ pet, style = "cat", styles[math.random(#styles)]
+ end
+ pets.create_pet(input.args, pet, style)
end, { nargs = 1 })
local function autocomplete(_, cmdline)
local matches = {}
local words = vim.split(cmdline, " ", { trimempty = true })
- local wd = debug.getinfo(1).source:sub(2):match("(.*nvim/)") .. "media/"
if not vim.endswith(cmdline, " ") then
table.remove(words, #words)