diff options
author | iurii plugatarov <[email protected]> | 2024-08-03 01:23:05 +0200 |
---|---|---|
committer | iurii plugatarov <[email protected]> | 2024-08-03 01:23:05 +0200 |
commit | 8132961a78def44238bb257bd96f4774fc87ca84 (patch) | |
tree | 55280641a5ebcd4d0bd4217f648d7433cad5888e | |
parent | 614b50a5cd2efcd1d88aa72c5a36aa4ef238dbfd (diff) | |
download | sketchbook.nvim-8132961a78def44238bb257bd96f4774fc87ca84.tar.gz |
remove templating main
Diffstat (limited to '')
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | lua/sketchbook/config.lua | 8 | ||||
-rw-r--r-- | lua/sketchbook/create_note.lua | 28 | ||||
-rw-r--r-- | lua/sketchbook/select_template.lua | 71 |
4 files changed, 17 insertions, 97 deletions
diff --git a/README.md b/README.md index 08a2e92..1e95724 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ This is quick and dirty implementation, something will probably won't work for y ## Features - **Quick Note Creation**: Quick note for random stuff -- **Template Selection**: You can predefine custom template for notes - **Note Searching**: telescope grep integration (if you have telescope installed ofc) - **Git Integration**: notes can be pushed and commited - **List Notes**: telescope integration that shows all existing notes @@ -61,6 +60,6 @@ require('lazy').setup({ ## TODO: -- [ ] improve git Integration -- [ ] fix telescope issues with indexing -- [ ] add auto indexing +- [x] improve git Integration +- [x] fix telescope issues with indexing +- [x] add auto indexing (solved with telescope) diff --git a/lua/sketchbook/config.lua b/lua/sketchbook/config.lua index 0f52993..9cd4ce8 100644 --- a/lua/sketchbook/config.lua +++ b/lua/sketchbook/config.lua @@ -3,13 +3,11 @@ local M = {} -- Default configuration M.defaults = { notes_directory = "~/notes", - templates_directory = "~/notes/templates/", keymaps = { create_note = "<leader>tnn", update_index = "<leader>tui", search_notes = "<leader>tns", list_notes = "<leader>tnl", - select_template = "<leader>tmp", toggle_quick_note = "<leader>qc", create_quick_note = "<leader>nq", open_entire_quick_note = "<leader>qo", @@ -50,12 +48,6 @@ function M.set_keymaps() ) vim.api.nvim_set_keymap( "n", - keymaps.select_template, - ':lua require("sketchbook.select_template").select_template()<CR>', - { 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()<CR>', { noremap = true, silent = true, desc = "Create a quick note buffer" } diff --git a/lua/sketchbook/create_note.lua b/lua/sketchbook/create_note.lua index d85e267..7bd2815 100644 --- a/lua/sketchbook/create_note.lua +++ b/lua/sketchbook/create_note.lua @@ -1,20 +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) + 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/select_template.lua b/lua/sketchbook/select_template.lua deleted file mode 100644 index e0c9f7e..0000000 --- a/lua/sketchbook/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 |