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
3 changes: 2 additions & 1 deletion lua/dotmd/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ end
function M.inbox(opts)
local utils = require("dotmd.utils")
local config = require("dotmd.config").config
local directories = require("dotmd.directories")

opts = utils.merge_default_create_file_opts(opts)

local inbox_path = vim.fn.expand(config.root_dir) .. "inbox.md"
local inbox_path = directories.get_root_dir() .. "inbox.md"

if vim.fn.filereadable(inbox_path) == 0 then
utils.write_file(inbox_path, "Inbox", config.templates.inbox)
Expand Down
11 changes: 11 additions & 0 deletions lua/dotmd/directories.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ function M.get_journal_dir()
return M.get_subdir("journal")
end

--- Get the root directory
---@return string path The path to the root directory
function M.get_root_dir()
local config = require("dotmd.config").config
local root_dir = vim.fn.expand(config.root_dir)

root_dir = vim.fn.fnamemodify(root_dir, ":p")

return root_dir .. "/"
end

--- Get directories for picker
---@param opts DotMd.PickOpts Options for picking the file
---@return string[] dirs The directories to pick from
Expand Down
8 changes: 8 additions & 0 deletions tests/directories_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ describe("dotmd.directories module", function()
end)
end)

describe("get_root_dir", function()
it("should return the root directory", function()
local root_dir = directories.get_root_dir()
local expected = test_config.root_dir .. "/"
assert.are.equal(expected, root_dir)
end)
end)

describe("get_picker_dirs", function()
it("should return all directories when type is 'all'", function()
local opts = { type = "all" }
Expand Down