From f24a3ab9744a3f50eb8cacc06d4ef4c5f96875db Mon Sep 17 00:00:00 2001 From: iurii plugatarov Date: Sat, 3 Aug 2024 00:19:11 +0300 Subject: fix --- lua/config.lua | 88 ------------------------------------ lua/create_note.lua | 20 --------- lua/git_sync.lua | 36 --------------- lua/init.lua | 17 ------- lua/quick_note.lua | 91 -------------------------------------- lua/search_notes.lua | 10 ----- lua/select_template.lua | 71 ----------------------------- lua/sketchbook/config.lua | 88 ++++++++++++++++++++++++++++++++++++ lua/sketchbook/create_note.lua | 20 +++++++++ lua/sketchbook/git_sync.lua | 36 +++++++++++++++ lua/sketchbook/init.lua | 17 +++++++ lua/sketchbook/quick_note.lua | 91 ++++++++++++++++++++++++++++++++++++++ lua/sketchbook/search_notes.lua | 10 +++++ lua/sketchbook/select_template.lua | 71 +++++++++++++++++++++++++++++ lua/sketchbook/update_index.lua | 22 +++++++++ lua/update_index.lua | 22 --------- 16 files changed, 355 insertions(+), 355 deletions(-) delete mode 100644 lua/config.lua delete mode 100644 lua/create_note.lua delete mode 100644 lua/git_sync.lua delete mode 100644 lua/init.lua delete mode 100644 lua/quick_note.lua delete mode 100644 lua/search_notes.lua delete mode 100644 lua/select_template.lua create mode 100644 lua/sketchbook/config.lua create mode 100644 lua/sketchbook/create_note.lua create mode 100644 lua/sketchbook/git_sync.lua create mode 100644 lua/sketchbook/init.lua create mode 100644 lua/sketchbook/quick_note.lua create mode 100644 lua/sketchbook/search_notes.lua create mode 100644 lua/sketchbook/select_template.lua create mode 100644 lua/sketchbook/update_index.lua delete mode 100644 lua/update_index.lua diff --git a/lua/config.lua b/lua/config.lua deleted file mode 100644 index 999245d..0000000 --- a/lua/config.lua +++ /dev/null @@ -1,88 +0,0 @@ -local M = {} - --- Default configuration -M.defaults = { - notes_directory = "~/notes", - templates_directory = "~/notes/templates/", - keymaps = { - create_note = "tnn", - update_index = "tui", - search_notes = "tns", - select_template = "ttn", - toggle_quick_note = "qc", - create_quick_note = "nq", - open_entire_quick_note = "qo", - commit_notes = "tgc", - push_notes = "tgp", -- New keymap for pushing notes - }, -} - -M.config = {} - -function M.setup(user_config) - M.config = vim.tbl_deep_extend("force", {}, M.defaults, user_config or {}) - vim.g.notes_directory = M.config.notes_directory - vim.g.notes_templates_dir = M.config.templates_directory - M.set_keymaps() -end - -function M.set_keymaps() - local keymaps = M.config.keymaps - - vim.api.nvim_set_keymap( - "n", - keymaps.create_note, - ':lua require("sketchbook.create_note").create_new_note()', - { noremap = true, silent = true, desc = "Create a new note" } - ) - vim.api.nvim_set_keymap( - "n", - keymaps.update_index, - ':lua require("sketchbook.update_index").update_index()', - { noremap = true, silent = true, desc = "Update notes index" } - ) - vim.api.nvim_set_keymap( - "n", - keymaps.search_notes, - ':lua require("sketchbook.search_notes").search_notes()', - { noremap = true, silent = true, desc = "Search notes" } - ) - vim.api.nvim_set_keymap( - "n", - keymaps.select_template, - ':lua require("sketchbook.select_template").select_template()', - { noremap = true, silent = true, desc = "Select a note template" } - ) - vim.api.nvim_set_keymap( - "n", - keymaps.create_quick_note, - ':lua require("sketchbook.quick_note").create_quick_note_window()', - { noremap = true, silent = true, desc = "Create a quick note buffer" } - ) - vim.api.nvim_set_keymap( - "n", - keymaps.toggle_quick_note, - ':lua require("sketchbook.quick_note").toggle_quick_note_window()', - { noremap = true, silent = true, desc = "Toggle quick note window" } - ) - vim.api.nvim_set_keymap( - "n", - keymaps.open_entire_quick_note, - ':lua require("sketchbook.quick_note").open_entire_quick_note()', - { noremap = true, silent = true, desc = "Open entire quick note" } - ) - vim.api.nvim_set_keymap( - "n", - keymaps.commit_notes, - ':lua require("sketchbook.git_sync").commit_notes()', - { noremap = true, silent = true, desc = "Commit notes to Git" } - ) - vim.api.nvim_set_keymap( - "n", - keymaps.push_notes, - ':lua require("sketchbook.git_sync").push_notes()', - { noremap = true, silent = true, desc = "Push notes to remote Git repository" } - ) -end - -return M diff --git a/lua/create_note.lua b/lua/create_note.lua deleted file mode 100644 index d85e267..0000000 --- a/lua/create_note.lua +++ /dev/null @@ -1,20 +0,0 @@ -local M = {} - -function M.create_new_note() - local notes_dir = vim.g.notes_directory or "~/notes/" - local filename = os.date "%Y-%m-%d_%H-%M-%S" .. ".md" - local filepath = vim.fn.expand(notes_dir) .. filename - local title = "Title " .. os.date "%Y-%m-%d %H:%M:%S" - local template = { - "# " .. title, - "", - } - local file = io.open(filepath, "w") - for _, line in ipairs(template) do - file:write(line .. "\n") - end - file:close() - vim.cmd("edit " .. filepath) -end - -return M diff --git a/lua/git_sync.lua b/lua/git_sync.lua deleted file mode 100644 index d19f024..0000000 --- a/lua/git_sync.lua +++ /dev/null @@ -1,36 +0,0 @@ -local M = {} - -function M.is_git_repo(path) - local git_dir = vim.fn.systemlist("git -C " .. path .. " rev-parse --is-inside-work-tree")[1] - return git_dir == "true" -end - -function M.commit_notes() - local notes_dir = vim.g.notes_directory or "~/notes/" - notes_dir = vim.fn.expand(notes_dir) - - if not M.is_git_repo(notes_dir) then - vim.notify("Note folder is not a Git repository.", vim.log.levels.WARN) - return - end - - local commit_message = "Update notes: " .. os.date "%Y-%m-%d %H:%M:%S" - vim.fn.system("git -C " .. notes_dir .. " add .") - vim.fn.system("git -C " .. notes_dir .. " commit -m '" .. commit_message .. "'") - vim.notify("Notes committed to Git repository.", vim.log.levels.INFO) -end - -function M.push_notes() - local notes_dir = vim.g.notes_directory or "~/notes/" - notes_dir = vim.fn.expand(notes_dir) - - if not M.is_git_repo(notes_dir) then - vim.notify("Note folder is not a Git repository.", vim.log.levels.WARN) - return - end - - vim.fn.system("git -C " .. notes_dir .. " push") - vim.notify("Notes pushed to remote repository.", vim.log.levels.INFO) -end - -return M diff --git a/lua/init.lua b/lua/init.lua deleted file mode 100644 index 421ae4c..0000000 --- a/lua/init.lua +++ /dev/null @@ -1,17 +0,0 @@ -local config = require("sketchbook.config") -local create_note = require("sketchbook.create_note") -local update_index = require("sketchbook.update_index") -local search_notes = require("sketchbook.search_notes") -local select_template = require("sketchbook.select_template") -local quick_note = require("sketchbook.quick_note") -local git_support = require("sketchbook.git_sync") - -local M = {} - -function M.setup(user_config) - config.setup(user_config) -end - -M.setup() - -return M diff --git a/lua/quick_note.lua b/lua/quick_note.lua deleted file mode 100644 index 1196faf..0000000 --- a/lua/quick_note.lua +++ /dev/null @@ -1,91 +0,0 @@ -local M = {} -local floating_win = nil - -local function get_win_config() - local width = math.floor(vim.o.columns * 0.8) - local height = math.floor(vim.o.lines * 0.8) - local row = math.floor((vim.o.lines - height) / 2) - local col = math.floor((vim.o.columns - width) / 2) - return { - relative = "editor", - width = width, - height = height, - row = row, - col = col, - style = "minimal", - border = "rounded", - } -end - -function M.create_quick_note_window() - if floating_win and vim.api.nvim_win_is_valid(floating_win) then - vim.api.nvim_set_current_win(floating_win) - return - end - - local buf = vim.api.nvim_create_buf(false, true) - floating_win = vim.api.nvim_open_win(buf, true, get_win_config()) - - vim.api.nvim_buf_set_option(buf, "buftype", "acwrite") - vim.api.nvim_buf_set_name(buf, "QuickNote") -end - -function M.toggle_quick_note_window() - if floating_win and vim.api.nvim_win_is_valid(floating_win) then - M.close_quick_note_window() - else - M.create_quick_note_window() - end -end - -function M.close_quick_note_window() - if floating_win and vim.api.nvim_win_is_valid(floating_win) then - local buf = vim.api.nvim_win_get_buf(floating_win) - M.prepend_to_quick_note() - vim.api.nvim_win_close(floating_win, true) - vim.api.nvim_buf_delete(buf, { force = true }) - end -end - -function M.prepend_to_quick_note() - local notes_dir = vim.g.notes_directory or "~/notes/" - local filepath = vim.fn.expand(notes_dir) .. "/quick_note.md" - local buf = vim.api.nvim_win_get_buf(floating_win) - local content = vim.api.nvim_buf_get_lines(buf, 0, -1, false) - - -- Add a separator and timestamp before the new content - local separator = "------------------------" - local timestamp = os.date "%Y-%m-%d %H:%M:%S" - table.insert(content, 1, "") - table.insert(content, 1, separator) - table.insert(content, 1, timestamp) - table.insert(content, 1, separator) - table.insert(content, 1, "") - - -- Check if quick_note.md exists, create it if it doesn't - if vim.fn.filereadable(filepath) == 0 then - vim.fn.writefile({}, filepath) - end - - local file_content = vim.fn.readfile(filepath) - for i = #file_content, 1, -1 do - table.insert(content, 1, file_content[i]) - end - - vim.fn.writefile(content, filepath) - print "Prepended content to quick_note.md" -end - -function M.open_entire_quick_note() - local notes_dir = vim.g.notes_directory or "~/notes/" - local filepath = vim.fn.expand(notes_dir) .. "/quick_note.md" - - if vim.fn.filereadable(filepath) == 0 then - print "No quick_note.md file found." - return - end - - vim.cmd("edit " .. filepath) -end - -return M diff --git a/lua/search_notes.lua b/lua/search_notes.lua deleted file mode 100644 index 152355e..0000000 --- a/lua/search_notes.lua +++ /dev/null @@ -1,10 +0,0 @@ -local M = {} - -function M.search_notes() - local notes_dir = vim.g.notes_directory or "~/notes/" - require("telescope.builtin").live_grep { - search_dirs = { vim.fn.expand(notes_dir) }, - } -end - -return M diff --git a/lua/select_template.lua b/lua/select_template.lua deleted file mode 100644 index e0c9f7e..0000000 --- a/lua/select_template.lua +++ /dev/null @@ -1,71 +0,0 @@ -local M = {} - -local templates_dir = vim.g.notes_templates_dir or "~/notes/templates/" - -function M.select_template() - templates_dir = vim.fn.expand(templates_dir) - local templates = vim.fn.readdir(templates_dir, function(name) - return name:match "%.md$" - end) - - if vim.tbl_isempty(templates) then - M.create_note_from_template(nil) - else - local template_files = {} - for _, template in ipairs(templates) do - table.insert(template_files, templates_dir .. template) - end - - require("telescope.pickers") - .new({}, { - prompt_title = "Select Template", - finder = require("telescope.finders").new_table { - results = template_files, - entry_maker = function(entry) - return { - value = entry, - display = vim.fn.fnamemodify(entry, ":t"), - ordinal = entry, - } - end, - }, - sorter = require("telescope.config").values.generic_sorter {}, - attach_mappings = function(prompt_bufnr, map) - local actions = require "telescope.actions" - local action_state = require "telescope.actions.state" - - actions.select_default:replace(function() - actions.close(prompt_bufnr) - local selection = action_state.get_selected_entry() - M.create_note_from_template(selection.value) - end) - - return true - end, - }) - :find() - end -end - -function M.create_note_from_template(template_path) - local notes_dir = vim.g.notes_directory or "~/notes/" - local filename = os.date "%Y-%m-%d_%H-%M-%S" .. ".md" - local filepath = vim.fn.expand(notes_dir) .. filename - vim.cmd("edit " .. filepath) - if template_path then - vim.cmd("0r " .. template_path) - else - local title = "Title " .. os.date "%Y-%m-%d %H:%M:%S" - local template = { - "# " .. title, - "", - } - local file = io.open(filepath, "w") - for _, line in ipairs(template) do - file:write(line .. "\n") - end - file:close() - end -end - -return M diff --git a/lua/sketchbook/config.lua b/lua/sketchbook/config.lua new file mode 100644 index 0000000..999245d --- /dev/null +++ b/lua/sketchbook/config.lua @@ -0,0 +1,88 @@ +local M = {} + +-- Default configuration +M.defaults = { + notes_directory = "~/notes", + templates_directory = "~/notes/templates/", + keymaps = { + create_note = "tnn", + update_index = "tui", + search_notes = "tns", + select_template = "ttn", + toggle_quick_note = "qc", + create_quick_note = "nq", + open_entire_quick_note = "qo", + commit_notes = "tgc", + push_notes = "tgp", -- New keymap for pushing notes + }, +} + +M.config = {} + +function M.setup(user_config) + M.config = vim.tbl_deep_extend("force", {}, M.defaults, user_config or {}) + vim.g.notes_directory = M.config.notes_directory + vim.g.notes_templates_dir = M.config.templates_directory + M.set_keymaps() +end + +function M.set_keymaps() + local keymaps = M.config.keymaps + + vim.api.nvim_set_keymap( + "n", + keymaps.create_note, + ':lua require("sketchbook.create_note").create_new_note()', + { noremap = true, silent = true, desc = "Create a new note" } + ) + vim.api.nvim_set_keymap( + "n", + keymaps.update_index, + ':lua require("sketchbook.update_index").update_index()', + { noremap = true, silent = true, desc = "Update notes index" } + ) + vim.api.nvim_set_keymap( + "n", + keymaps.search_notes, + ':lua require("sketchbook.search_notes").search_notes()', + { noremap = true, silent = true, desc = "Search notes" } + ) + vim.api.nvim_set_keymap( + "n", + keymaps.select_template, + ':lua require("sketchbook.select_template").select_template()', + { noremap = true, silent = true, desc = "Select a note template" } + ) + vim.api.nvim_set_keymap( + "n", + keymaps.create_quick_note, + ':lua require("sketchbook.quick_note").create_quick_note_window()', + { noremap = true, silent = true, desc = "Create a quick note buffer" } + ) + vim.api.nvim_set_keymap( + "n", + keymaps.toggle_quick_note, + ':lua require("sketchbook.quick_note").toggle_quick_note_window()', + { noremap = true, silent = true, desc = "Toggle quick note window" } + ) + vim.api.nvim_set_keymap( + "n", + keymaps.open_entire_quick_note, + ':lua require("sketchbook.quick_note").open_entire_quick_note()', + { noremap = true, silent = true, desc = "Open entire quick note" } + ) + vim.api.nvim_set_keymap( + "n", + keymaps.commit_notes, + ':lua require("sketchbook.git_sync").commit_notes()', + { noremap = true, silent = true, desc = "Commit notes to Git" } + ) + vim.api.nvim_set_keymap( + "n", + keymaps.push_notes, + ':lua require("sketchbook.git_sync").push_notes()', + { noremap = true, silent = true, desc = "Push notes to remote Git repository" } + ) +end + +return M diff --git a/lua/sketchbook/create_note.lua b/lua/sketchbook/create_note.lua new file mode 100644 index 0000000..d85e267 --- /dev/null +++ b/lua/sketchbook/create_note.lua @@ -0,0 +1,20 @@ +local M = {} + +function M.create_new_note() + local notes_dir = vim.g.notes_directory or "~/notes/" + local filename = os.date "%Y-%m-%d_%H-%M-%S" .. ".md" + local filepath = vim.fn.expand(notes_dir) .. filename + local title = "Title " .. os.date "%Y-%m-%d %H:%M:%S" + local template = { + "# " .. title, + "", + } + local file = io.open(filepath, "w") + for _, line in ipairs(template) do + file:write(line .. "\n") + end + file:close() + vim.cmd("edit " .. filepath) +end + +return M diff --git a/lua/sketchbook/git_sync.lua b/lua/sketchbook/git_sync.lua new file mode 100644 index 0000000..d19f024 --- /dev/null +++ b/lua/sketchbook/git_sync.lua @@ -0,0 +1,36 @@ +local M = {} + +function M.is_git_repo(path) + local git_dir = vim.fn.systemlist("git -C " .. path .. " rev-parse --is-inside-work-tree")[1] + return git_dir == "true" +end + +function M.commit_notes() + local notes_dir = vim.g.notes_directory or "~/notes/" + notes_dir = vim.fn.expand(notes_dir) + + if not M.is_git_repo(notes_dir) then + vim.notify("Note folder is not a Git repository.", vim.log.levels.WARN) + return + end + + local commit_message = "Update notes: " .. os.date "%Y-%m-%d %H:%M:%S" + vim.fn.system("git -C " .. notes_dir .. " add .") + vim.fn.system("git -C " .. notes_dir .. " commit -m '" .. commit_message .. "'") + vim.notify("Notes committed to Git repository.", vim.log.levels.INFO) +end + +function M.push_notes() + local notes_dir = vim.g.notes_directory or "~/notes/" + notes_dir = vim.fn.expand(notes_dir) + + if not M.is_git_repo(notes_dir) then + vim.notify("Note folder is not a Git repository.", vim.log.levels.WARN) + return + end + + vim.fn.system("git -C " .. notes_dir .. " push") + vim.notify("Notes pushed to remote repository.", vim.log.levels.INFO) +end + +return M diff --git a/lua/sketchbook/init.lua b/lua/sketchbook/init.lua new file mode 100644 index 0000000..421ae4c --- /dev/null +++ b/lua/sketchbook/init.lua @@ -0,0 +1,17 @@ +local config = require("sketchbook.config") +local create_note = require("sketchbook.create_note") +local update_index = require("sketchbook.update_index") +local search_notes = require("sketchbook.search_notes") +local select_template = require("sketchbook.select_template") +local quick_note = require("sketchbook.quick_note") +local git_support = require("sketchbook.git_sync") + +local M = {} + +function M.setup(user_config) + config.setup(user_config) +end + +M.setup() + +return M diff --git a/lua/sketchbook/quick_note.lua b/lua/sketchbook/quick_note.lua new file mode 100644 index 0000000..1196faf --- /dev/null +++ b/lua/sketchbook/quick_note.lua @@ -0,0 +1,91 @@ +local M = {} +local floating_win = nil + +local function get_win_config() + local width = math.floor(vim.o.columns * 0.8) + local height = math.floor(vim.o.lines * 0.8) + local row = math.floor((vim.o.lines - height) / 2) + local col = math.floor((vim.o.columns - width) / 2) + return { + relative = "editor", + width = width, + height = height, + row = row, + col = col, + style = "minimal", + border = "rounded", + } +end + +function M.create_quick_note_window() + if floating_win and vim.api.nvim_win_is_valid(floating_win) then + vim.api.nvim_set_current_win(floating_win) + return + end + + local buf = vim.api.nvim_create_buf(false, true) + floating_win = vim.api.nvim_open_win(buf, true, get_win_config()) + + vim.api.nvim_buf_set_option(buf, "buftype", "acwrite") + vim.api.nvim_buf_set_name(buf, "QuickNote") +end + +function M.toggle_quick_note_window() + if floating_win and vim.api.nvim_win_is_valid(floating_win) then + M.close_quick_note_window() + else + M.create_quick_note_window() + end +end + +function M.close_quick_note_window() + if floating_win and vim.api.nvim_win_is_valid(floating_win) then + local buf = vim.api.nvim_win_get_buf(floating_win) + M.prepend_to_quick_note() + vim.api.nvim_win_close(floating_win, true) + vim.api.nvim_buf_delete(buf, { force = true }) + end +end + +function M.prepend_to_quick_note() + local notes_dir = vim.g.notes_directory or "~/notes/" + local filepath = vim.fn.expand(notes_dir) .. "/quick_note.md" + local buf = vim.api.nvim_win_get_buf(floating_win) + local content = vim.api.nvim_buf_get_lines(buf, 0, -1, false) + + -- Add a separator and timestamp before the new content + local separator = "------------------------" + local timestamp = os.date "%Y-%m-%d %H:%M:%S" + table.insert(content, 1, "") + table.insert(content, 1, separator) + table.insert(content, 1, timestamp) + table.insert(content, 1, separator) + table.insert(content, 1, "") + + -- Check if quick_note.md exists, create it if it doesn't + if vim.fn.filereadable(filepath) == 0 then + vim.fn.writefile({}, filepath) + end + + local file_content = vim.fn.readfile(filepath) + for i = #file_content, 1, -1 do + table.insert(content, 1, file_content[i]) + end + + vim.fn.writefile(content, filepath) + print "Prepended content to quick_note.md" +end + +function M.open_entire_quick_note() + local notes_dir = vim.g.notes_directory or "~/notes/" + local filepath = vim.fn.expand(notes_dir) .. "/quick_note.md" + + if vim.fn.filereadable(filepath) == 0 then + print "No quick_note.md file found." + return + end + + vim.cmd("edit " .. filepath) +end + +return M diff --git a/lua/sketchbook/search_notes.lua b/lua/sketchbook/search_notes.lua new file mode 100644 index 0000000..152355e --- /dev/null +++ b/lua/sketchbook/search_notes.lua @@ -0,0 +1,10 @@ +local M = {} + +function M.search_notes() + local notes_dir = vim.g.notes_directory or "~/notes/" + require("telescope.builtin").live_grep { + search_dirs = { vim.fn.expand(notes_dir) }, + } +end + +return M diff --git a/lua/sketchbook/select_template.lua b/lua/sketchbook/select_template.lua new file mode 100644 index 0000000..e0c9f7e --- /dev/null +++ b/lua/sketchbook/select_template.lua @@ -0,0 +1,71 @@ +local M = {} + +local templates_dir = vim.g.notes_templates_dir or "~/notes/templates/" + +function M.select_template() + templates_dir = vim.fn.expand(templates_dir) + local templates = vim.fn.readdir(templates_dir, function(name) + return name:match "%.md$" + end) + + if vim.tbl_isempty(templates) then + M.create_note_from_template(nil) + else + local template_files = {} + for _, template in ipairs(templates) do + table.insert(template_files, templates_dir .. template) + end + + require("telescope.pickers") + .new({}, { + prompt_title = "Select Template", + finder = require("telescope.finders").new_table { + results = template_files, + entry_maker = function(entry) + return { + value = entry, + display = vim.fn.fnamemodify(entry, ":t"), + ordinal = entry, + } + end, + }, + sorter = require("telescope.config").values.generic_sorter {}, + attach_mappings = function(prompt_bufnr, map) + local actions = require "telescope.actions" + local action_state = require "telescope.actions.state" + + actions.select_default:replace(function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + M.create_note_from_template(selection.value) + end) + + return true + end, + }) + :find() + end +end + +function M.create_note_from_template(template_path) + local notes_dir = vim.g.notes_directory or "~/notes/" + local filename = os.date "%Y-%m-%d_%H-%M-%S" .. ".md" + local filepath = vim.fn.expand(notes_dir) .. filename + vim.cmd("edit " .. filepath) + if template_path then + vim.cmd("0r " .. template_path) + else + local title = "Title " .. os.date "%Y-%m-%d %H:%M:%S" + local template = { + "# " .. title, + "", + } + local file = io.open(filepath, "w") + for _, line in ipairs(template) do + file:write(line .. "\n") + end + file:close() + end +end + +return M diff --git a/lua/sketchbook/update_index.lua b/lua/sketchbook/update_index.lua new file mode 100644 index 0000000..1a6044e --- /dev/null +++ b/lua/sketchbook/update_index.lua @@ -0,0 +1,22 @@ +local M = {} + +function M.update_index() + local notes_dir = vim.g.notes_directory or "~/notes/" + notes_dir = vim.fn.expand(notes_dir) + local index_file = notes_dir .. "index.md" + local notes = vim.fn.globpath(notes_dir, "*.md", false, true) + local content = { "# Index", "" } + for _, note in ipairs(notes) do + if vim.fn.fnamemodify(note, ":t") ~= "index.md" then + table.insert(content, "- [" .. vim.fn.fnamemodify(note, ":t:r") .. "](" .. note .. ")") + end + end + local file = io.open(index_file, "w") + for _, line in ipairs(content) do + file:write(line .. "\n") + end + file:close() + print "Index updated" +end + +return M diff --git a/lua/update_index.lua b/lua/update_index.lua deleted file mode 100644 index 1a6044e..0000000 --- a/lua/update_index.lua +++ /dev/null @@ -1,22 +0,0 @@ -local M = {} - -function M.update_index() - local notes_dir = vim.g.notes_directory or "~/notes/" - notes_dir = vim.fn.expand(notes_dir) - local index_file = notes_dir .. "index.md" - local notes = vim.fn.globpath(notes_dir, "*.md", false, true) - local content = { "# Index", "" } - for _, note in ipairs(notes) do - if vim.fn.fnamemodify(note, ":t") ~= "index.md" then - table.insert(content, "- [" .. vim.fn.fnamemodify(note, ":t:r") .. "](" .. note .. ")") - end - end - local file = io.open(index_file, "w") - for _, line in ipairs(content) do - file:write(line .. "\n") - end - file:close() - print "Index updated" -end - -return M -- cgit 1.4.1-2-gfad0