Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ So I started building dotmd — something small and focused. I wanted a way to w
- 📄 **Smart File Creation:** Easily create files with optional templates and unique file naming.
- 📝 **Daily Todos:** Auto-generate daily todo files and rollover unchecked tasks from the nearest previous day.
- 📅 **Daily Journals:** Quickly generate a markdown journal entry for the current date.
- 🔍 **Note Picker:** Search or grep your notes across all categories using `vim.ui.select` or the `snacks.nvim` plugin if available.
- 🔍 **Note Picker:** Search or grep your notes across all categories using `vim.ui.select` or the `snacks.nvim` or `fzf-lua` or `telescope.nvim` picker.
- 📌 **Inbox:** Quick dump zone for thoughts, tasks, and references.
- 🧭 **Smart Navigation:** Move to the nearest previous/next `todo` or `journal` entry automagically.
- 🔧 **Fully Configurable:** Customize directories, templates, and behavior.
Expand Down Expand Up @@ -70,8 +70,11 @@ require("dotmd").setup({
- Neovim 0.9+ with Lua support
- The following CLI tools must be available in your $PATH:
- `find`: for listing files across note directories
- `grep`: for searching files across note directories
- Optional but recommended:
- [snacks.nvim](https://github.com/folke/snacks.nvim): For better note picking and grepping
- [fzf-lua](https://github.com/ibhagwan/fzf-lua): For better note picking and grepping
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim): For better note picking and grepping

## ⚙️ Configuration

Expand All @@ -84,10 +87,12 @@ require("dotmd").setup({

```lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.PickerType "telescope" | "fzf" | "snacks" Picker type

---@class DotMd.Config
---@field root_dir? string Root directory of dotmd, default is `~/dotmd`
---@field default_split? DotMd.Split Split direction for new or existing files, default is `none`
---@field picker? DotMd.PickerType Picker type, default is `nil`
---@field rollover_todo? boolean Rollover the nearest previous unchecked todos to today's date, default is `true`
---@field dir_names? DotMd.Config.DirNames
---@field templates? Dotmd.Config.Templates
Expand All @@ -106,6 +111,7 @@ require("dotmd").setup({
root_dir = "~/dotmd",
default_split = "none",
rollover_todo = true,
picker = nil,
dir_names = {
notes = "notes",
todo = "todo",
Expand Down Expand Up @@ -189,8 +195,11 @@ See the example below for how to configure **dotmd.nvim**.
"DotMdPick",
"DotMdOpen",
},
event = "VeryLazy",
---@type DotMd.Config
opts = {},
opts = {
picker = "snacks" -- or "fzf" or "telescope" based on your preference
},
keys = {
{
"<leader>nc",
Expand Down Expand Up @@ -402,8 +411,8 @@ When you create a new journal file, **dotmd.nvim**:

### Picker

1. Uses `vim.ui.select` for file list or grep.
2. If `snacks.nvim` is installed, uses `snacks.picker.grep()` or `snacks.picker.files()` for enhanced UX.
1. Uses `vim.ui.select` for file list or grep as fallback or default.
2. You can choose to use `snacks.nvim`, `fzf-lua`, or `telescope.nvim` for the picker based on your preference.
3. Can filter by file type (notes, todo, journal, or all).

### Open
Expand Down Expand Up @@ -517,15 +526,17 @@ You can also use the command `:DotMdInbox` to open the central `inbox.md`. And i
Pick or search files in **dotmd.nvim** directories by `type`.

> [!note]
> Recommended to use `snacks.nvim` for enhanced UX, else will fallback to `vim.ui.select`.
> Recommended to any of the pickers `snacks.nvim`, `fzf-lua`, or `telescope.nvim` for enhanced UX, else will fallback to `vim.ui.select`.

> [!warning]
> `grep` option is not supported and will do nothing for the fallback.

```lua
---@alias DotMd.PickType "notes" | "todos" | "journal" | "all" Pick type
---@alias DotMd.PickerType "telescope" | "fzf" | "snacks" Picker type

---@class DotMd.PickOpts
---@field picker? DotMd.PickerType Picker type, default is based on `picker` in config
---@field type? DotMd.PickType Pick type, default is `notes`
---@field grep? boolean Grep the selected type directory for a string, default is false

Expand All @@ -535,8 +546,6 @@ require("dotmd").pick(opts)

You can also use the command `:DotMdPick` to pick or search files in **dotmd.nvim** directories by `type`. And it supports the same options.

Since I am exclusively using `snacks.nvim`, if you need some other picker to be integrated, feel free to help out and send in a PR for it.

### Navigate to Previous/Next Nearest `journal` or `todo` File

Go to nearest previous/next date-based file.
Expand Down
26 changes: 17 additions & 9 deletions doc/dotmd.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FEATURES *dotmd.nvim-dotmd.nvim-features*
- **Smart File Creation:** Easily create files with optional templates and unique file naming.
- **Daily Todos:** Auto-generate daily todo files and rollover unchecked tasks from the nearest previous day.
- **Daily Journals:** Quickly generate a markdown journal entry for the current date.
- **Note Picker:** Search or grep your notes across all categories using `vim.ui.select` or the `snacks.nvim` plugin if available.
- **Note Picker:** Search or grep your notes across all categories using `vim.ui.select` or the `snacks.nvim` or `fzf-lua` or `telescope.nvim` picker.
- **Inbox:** Quick dump zone for thoughts, tasks, and references.
- **Smart Navigation:** Move to the nearest previous/next `todo` or `journal` entry automagically.
- **Fully Configurable:** Customize directories, templates, and behavior.
Expand Down Expand Up @@ -64,8 +64,11 @@ REQUIREMENTS ~
- Neovim0.9+ with Lua support
- The following CLI tools must be available in your $PATH:
- `find`for listing files across note directories
- `grep`for searching files across note directories
- Optional but recommended:
- snacks.nvim <https://github.com/folke/snacks.nvim>For better note picking and grepping
- fzf-lua <https://github.com/ibhagwan/fzf-lua>For better note picking and grepping
- telescope.nvim <https://github.com/nvim-telescope/telescope.nvim>For better note picking and grepping


CONFIGURATION *dotmd.nvim-dotmd.nvim-configuration*
Expand All @@ -81,10 +84,12 @@ DEFAULT OPTIONS ~

>lua
---@alias DotMd.Split "vertical" | "horizontal" | "none" Split direction
---@alias DotMd.PickerType "telescope" | "fzf" | "snacks" Picker type

---@class DotMd.Config
---@field root_dir? string Root directory of dotmd, default is `~/dotmd`
---@field default_split? DotMd.Split Split direction for new or existing files, default is `none`
---@field picker? DotMd.PickerType Picker type, default is `nil`
---@field rollover_todo? boolean Rollover the nearest previous unchecked todos to today's date, default is `true`
---@field dir_names? DotMd.Config.DirNames
---@field templates? Dotmd.Config.Templates
Expand All @@ -103,6 +108,7 @@ DEFAULT OPTIONS ~
root_dir = "~/dotmd",
default_split = "none",
rollover_todo = true,
picker = nil,
dir_names = {
notes = "notes",
todo = "todo",
Expand Down Expand Up @@ -187,8 +193,11 @@ See the example below for how to configure **dotmd.nvim**.
"DotMdPick",
"DotMdOpen",
},
event = "VeryLazy",
---@type DotMd.Config
opts = {},
opts = {
picker = "snacks" -- or "fzf" or "telescope" based on your preference
},
keys = {
{
"<leader>nc",
Expand Down Expand Up @@ -411,8 +420,8 @@ When you create a new journal file, **dotmd.nvim**

PICKER ~

1. Uses `vim.ui.select` for file list or grep.
2. If `snacks.nvim` is installed, uses `snacks.picker.grep()` or `snacks.picker.files()` for enhanced UX.
1. Uses `vim.ui.select` for file list or grep as fallback or default.
2. You can choose to use `snacks.nvim`, `fzf-lua`, or `telescope.nvim` for the picker based on your preference.
3. Can filter by file type (notes, todo, journal, or all).


Expand Down Expand Up @@ -539,14 +548,16 @@ PICK ~
Pick or search files in **dotmd.nvim** directories by `type`.


[!note] Recommended to use `snacks.nvim` for enhanced UX, else will fallback to
`vim.ui.select`.
[!note] Recommended to any of the pickers `snacks.nvim`, `fzf-lua`, or
`telescope.nvim` for enhanced UX, else will fallback to `vim.ui.select`.

[!warning] `grep` option is not supported and will do nothing for the fallback.
>lua
---@alias DotMd.PickType "notes" | "todos" | "journal" | "all" Pick type
---@alias DotMd.PickerType "telescope" | "fzf" | "snacks" Picker type

---@class DotMd.PickOpts
---@field picker? DotMd.PickerType Picker type, default is based on `picker` in config
---@field type? DotMd.PickType Pick type, default is `notes`
---@field grep? boolean Grep the selected type directory for a string, default is false

Expand All @@ -557,9 +568,6 @@ Pick or search files in **dotmd.nvim** directories by `type`.
You can also use the command `:DotMdPick` to pick or search files in
**dotmd.nvim** directories by `type`. And it supports the same options.

Since I am exclusively using `snacks.nvim`, if you need some other picker to be
integrated, feel free to help out and send in a PR for it.


NAVIGATE TO PREVIOUS/NEXT NEAREST JOURNAL OR TODO FILE ~

Expand Down
46 changes: 9 additions & 37 deletions lua/dotmd/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,13 @@ end
---@return nil
function M.pick(opts)
local directories = require("dotmd.directories")
local picker = require("dotmd.picker")
local native_select_files = require("dotmd.prompt").native_select_files

opts = opts or {}
opts.type = opts.type or "notes"
opts.grep = opts.grep or false
opts.picker = opts.picker or require("dotmd.config").config.picker

local dirs = directories.get_picker_dirs(opts.type)

Expand All @@ -192,47 +195,16 @@ function M.pick(opts)
local prompt_prefix = opts.grep and "Grep for" or "Pick a"
local prompt = prompt_prefix .. prompt_name_type .. ": "

-- Use snacks picker if exists
local snacks_ok, snacks = pcall(require, "snacks")
if snacks_ok and snacks and snacks.picker then
if opts.grep then
snacks.picker.grep({ dirs = dirs, prompt = prompt })
else
snacks.picker.files({ dirs = dirs, prompt = prompt })
if opts.picker then
local picker_ok = picker[opts.picker](opts, dirs, prompt)

if picker_ok then
return
end
return
end

-- else use vim.ui.select
local function fuzzy_filter(query, items)
query = query:lower()
return vim.tbl_filter(function(item)
return item.display:lower():find(query, 1, true) ~= nil
end, items)
end

local items = directories.prepare_items_for_select(dirs)
if #items == 0 then
vim.notify(
"No" .. prompt_name_type .. "files found in specified directories",
vim.log.levels.WARN
)
return
end

vim.ui.select(items, {
prompt = prompt,
format_item = function(item)
return item.display
end,
kind = "note",
fuzzy = true,
filter = fuzzy_filter,
}, function(selected)
if selected then
vim.cmd("edit " .. vim.fn.fnameescape(selected.value))
end
end)
native_select_files(dirs, prompt_name_type, prompt)
end

---Navigate to the nearest previous/next date-based file
Expand Down
1 change: 1 addition & 0 deletions lua/dotmd/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local defaults = {
root_dir = "~/dotmd",
default_split = "none",
rollover_todo = true,
picker = nil,
dir_names = {
notes = "notes",
todo = "todo",
Expand Down
47 changes: 28 additions & 19 deletions lua/dotmd/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ function M.check()
)
end

if vim.fn.executable("grep") == 1 then
report_status("ok", "'grep' command found.")
else
report_status("error", "'grep' command not found. Please install grep.")
end

separator("dotmd - Optional Dependencies")
-- Check for optional dependency: snacks.nvim

if pcall(require, "snacks") then
report_status("ok", "snacks.nvim is installed (optional dependency).")
else
Expand All @@ -50,6 +56,27 @@ function M.check()
)
end

if pcall(require, "fzf-lua") then
report_status("ok", "fzf-lua is installed (optional dependency).")
else
report_status(
"warn",
"fzf-lua not found. It's optional, but recommended for enhanced fuzzy finding."
)
end

if pcall(require, "telescope") then
report_status(
"ok",
"telescope.nvim is installed (optional dependency)."
)
else
report_status(
"warn",
"telescope.nvim not found. It's optional, but recommended for enhanced fuzzy finding."
)
end

separator("dotmd - Root Directory Check")
-- Check the configured root directory
local ok, config = pcall(require, "dotmd.config")
Expand All @@ -70,24 +97,6 @@ function M.check()
.. ". It will be created on demand."
)
end

separator("dotmd - Module Load Checks")
-- List required dotmd modules to check if they load successfully.
local required_modules = {
"dotmd.commands",
"dotmd.config",
"dotmd.directories",
"dotmd.todos",
"dotmd.utils",
}
for _, mod in ipairs(required_modules) do
local mod_ok, _ = pcall(require, mod)
if mod_ok then
report_status("ok", "Module '" .. mod .. "' loaded successfully.")
else
report_status("error", "Module '" .. mod .. "' failed to load.")
end
end
end

return M
Loading