Skip to content

Commit

Permalink
feat: todos search
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasYOY committed Nov 12, 2023
1 parent 6d77193 commit 50c846d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ return {
vim.keymap.set("n", "<leader>nfj", "<cmd>ObsNvimFindInJournal<cr>")
vim.keymap.set("n", "<leader>nff", "<cmd>ObsNvimFindNote<cr>")
vim.keymap.set("n", "<leader>nfg", "<cmd>ObsNvimFindInNotes<cr>")
vim.keymap.set(
"n",
"<leader>nft",
"<cmd>ObsNvimFindTodosInNotes<cr>"
)
end,
},
}
Expand Down Expand Up @@ -96,7 +101,8 @@ Example mappings configuration may be found [here](https://github.com/IlyasYOY/d
- *Opens daily note.* `:ObsNvimDailyNote` creates one if doesn't exist.
- *Telescope find notes.* `:ObsNvimFindNote`.
- *Telescope find journal notes.* `:ObsNvimFindInJournal`.
- *Telescope live-grep through notes.* `:ObsNvimFinInNotes`.
- *Telescope live-grep through notes.* `:ObsNvimFindInNotes`.
- *Telescope live-grep through tasks prepared search.* `:ObsNvimFindTodosInNotes`.
- *Telescope through back-links.* `:ObsNvimBacklinks`.
- *Renames current note.* `:ObsNvimRename` updates links to the note. I advice you to rename notes inside **Obsidian** for important notes with lots of back-links.
- *Move note to directory from search.* `:ObsNvimMove` launches telescope to find directory to move current note to.
Expand Down
6 changes: 6 additions & 0 deletions lua/obs/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ end, {
desc = "Find in notes",
})

vim.api.nvim_create_user_command("ObsNvimFindTodosInNotes", function()
obs.vault:find_todos()
end, {
desc = "Find todos in notes",
})

vim.api.nvim_create_user_command("ObsNvimBacklinks", function()
obs.vault:run_if_note(function()
obs.vault:find_current_note_backlinks()
Expand Down
4 changes: 3 additions & 1 deletion lua/obs/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ end
---@param title string
---@param path string to search files at
---@param type_filter string? file type, check rg docs typelist on the matter
function M.grep_files(title, path, type_filter)
---@param default_text string? default query to run search with
function M.grep_files(title, path, type_filter, default_text)
if type_filter == nil then
type_filter = "md"
end

return builtin.live_grep {
cwd = path,
default_text = default_text,
prompt_title = title,
type_filter = type_filter,
}
Expand Down
5 changes: 5 additions & 0 deletions lua/obs/vault.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ function Vault:find_note()
obs_telescope.find_files("Find notes", self._home_path:expand())
end

function Vault:find_todos()
local request_string = "- \\[[x ]\\]"
obs_telescope.grep_files("Find TODOs", self._home_path:expand(), nil, request_string)
end

function Vault:find_current_note_backlinks()
local current_note = File:new(core.current_working_file())
self:find_backlinks(current_note:name())
Expand Down

0 comments on commit 50c846d

Please sign in to comment.