Impl functions to move and to surface random notes.
parent
86e308de8f
commit
0071a636cc
|
@ -58,9 +58,10 @@ wk.register({
|
|||
o = { "<cmd>VotionOpen<cr>", "Open" },
|
||||
g = { "<cmd>VotionGrep<cr>", "Grep" },
|
||||
i = { "<cmd>VotionInsert<cr>", "Insert" },
|
||||
r = { "<cmd>VotionRename<cr>", "Rename" },
|
||||
m = { "<cmd>VotionMove<cr>", "Move" },
|
||||
f = { "<cmd>VotionFollow<cr>", "Follow" },
|
||||
d = { "<cmd>VotionDelete<cr>", "Delete" },
|
||||
r = { "<cmd>VotionRandom<cr>", "Random" },
|
||||
},
|
||||
}, { prefix = "<leader>" })
|
||||
|
||||
|
|
|
@ -111,6 +111,54 @@ function votion_delete()
|
|||
end
|
||||
end
|
||||
|
||||
function votion_random()
|
||||
local scan = require('plenary.scandir')
|
||||
local exclude_dirs = {
|
||||
"calendar/archive",
|
||||
}
|
||||
|
||||
local all_files = scan.scan_dir(votion_directory, {
|
||||
hidden = false,
|
||||
add_dirs = false,
|
||||
depth = 10,
|
||||
search_pattern = "%.md$",
|
||||
})
|
||||
|
||||
local files = {}
|
||||
for _, file in ipairs(all_files) do
|
||||
local should_exclude = false
|
||||
for _, exclude_dir in ipairs(exclude_dirs) do
|
||||
if file:match(votion_directory .. "/" .. exclude_dir) then
|
||||
should_exclude = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not should_exclude and file:match("%.md$") then
|
||||
table.insert(files, file)
|
||||
end
|
||||
end
|
||||
|
||||
if #files == 0 then
|
||||
print("No markdown files found in " .. votion_directory .. ".")
|
||||
return
|
||||
end
|
||||
|
||||
math.randomseed(os.time())
|
||||
local random_index = math.random(#files)
|
||||
local random_file = files[random_index]
|
||||
vim.api.nvim_command('edit ' .. random_file)
|
||||
end
|
||||
|
||||
function votion_move()
|
||||
local current_file = vim.api.nvim_buf_get_name(0)
|
||||
local current_dir = current_file:match("(.*/)")
|
||||
if current_dir then
|
||||
vim.api.nvim_command("Oil " .. current_dir)
|
||||
else
|
||||
print("Current buffer does not have a directory.")
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_command("command! VotionNew lua votion_new()")
|
||||
vim.api.nvim_command("command! VotionOpen lua votion_open()")
|
||||
vim.api.nvim_command("command! VotionGrep lua votion_grep()")
|
||||
|
@ -118,3 +166,5 @@ vim.api.nvim_command("command! VotionRename lua votion_rename()")
|
|||
vim.api.nvim_command("command! VotionFollow lua votion_follow()")
|
||||
vim.api.nvim_command("command! VotionDelete lua votion_delete()")
|
||||
vim.api.nvim_command("command! VotionInsert lua votion_insert()")
|
||||
vim.api.nvim_command("command! VotionRandom lua votion_random()")
|
||||
vim.api.nvim_command("command! VotionMove lua votion_move()")
|
||||
|
|
Loading…
Reference in New Issue