Adds RandomFile generator

This commit is contained in:
Michel Fedde 2025-02-12 00:30:56 +01:00
parent c5935a5692
commit 8c69a2f7e5
3 changed files with 2027 additions and 0 deletions

View file

@ -0,0 +1,27 @@
local fs = require("functions.fs")
local function tocamel(s)
return string.upper(string.sub(s, 1, 1)) .. string.sub(s, 2)
end
vim.api.nvim_create_user_command("CreateRandomFile", function()
local words = vim.fn.readfile(vim.fs.normalize("~/.config/nvim/assets/words.txt"))
local wordsRequests = math.random(2, 4)
local wordsFinal = ""
for i = 1, wordsRequests do
local word = words[math.random(#words)]
wordsFinal = wordsFinal .. tocamel(word)
end
local currentPath = fs.getCurrentPath()
local directory = currentPath
if vim.fn.isdirectory(currentPath) == 0 then
directory = vim.fs.dirname(currentPath)
end
local path = vim.fs.joinpath(directory, wordsFinal .. ".md")
os.execute(string.format('touch "%s"', path))
end, {})