idk
This commit is contained in:
parent
e064cecd90
commit
7c7ca903b5
@ -1,6 +1,6 @@
|
||||
{
|
||||
"Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
|
||||
"LuaSnip": { "branch": "master", "commit": "de10d8414235b0a8cabfeba60d07c24304e71f5c" },
|
||||
"LuaSnip": { "branch": "master", "commit": "21f74f7ba8c49f95f9d7c8293b147c2901dd2d3a" },
|
||||
"auto-session": { "branch": "main", "commit": "3b5d8947cf16ac582ef00443ede4cdd3dfa23af9" },
|
||||
"base46": { "branch": "v2.0", "commit": "85de6cdb2d3c85d0aee53aea0569e73fdaf3df4e" },
|
||||
"cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" },
|
||||
@ -19,13 +19,13 @@
|
||||
"nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" },
|
||||
"nvim-colorizer.lua": { "branch": "master", "commit": "51cf7c995ed1eb6642aecf19067ee634fa1b6ba2" },
|
||||
"nvim-dap": { "branch": "master", "commit": "7891b01beedc37cef4eaf2e92563bd0a5b6e9c58" },
|
||||
"nvim-dap": { "branch": "master", "commit": "7523676a4be17644587aa47e4d42f6f7646d4727" },
|
||||
"nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "a3deebbd110016f50cc66b7b256120072f3804db" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "c8b90ae5cbe21d547b342b05c9266dcb8ca0de8f" },
|
||||
"nvim-notify": { "branch": "master", "commit": "8701bece920b38ea289b457f902e2ad184131a5d" },
|
||||
"nvim-tree.lua": { "branch": "master", "commit": "fefa335f1c8f690eb668a1efd18ee4fc6d64cd3e" },
|
||||
"nvim-tree.lua": { "branch": "master", "commit": "e179ad2f83b5955ab0af653069a493a1828c2697" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "f66cdfef5e84112045b9ebc3119fee9bddb3c687" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "6e51ca170563330e063720449c21f43e27ca0bc1" },
|
||||
"nvterm": { "branch": "main", "commit": "9d7ba3b6e368243175d38e1ec956e0476fd86ed9" },
|
||||
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
|
||||
"rust.vim": { "branch": "master", "commit": "889b9a7515db477f4cb6808bef1769e53493c578" },
|
||||
|
||||
@ -10,7 +10,6 @@ local function iso_utc()
|
||||
return os.date "!%Y-%m-%dT%H:%M:%SZ"
|
||||
end
|
||||
|
||||
-- ---------- create file helper ----------
|
||||
local function write_if_missing(path, lines)
|
||||
if vim.fn.filereadable(path) == 0 then
|
||||
local fh = io.open(path, "w")
|
||||
@ -25,11 +24,10 @@ local function write_if_missing(path, lines)
|
||||
end
|
||||
|
||||
-- ---------- :JrnlNew ----------
|
||||
-- Creates a new journal entry with JRNL-YYYYMMDD-HHMMSS.md format
|
||||
local function new_journal_note()
|
||||
local timestamp = os.date "%Y%m%d-%H%M%S"
|
||||
local date_title = os.date "%A, %B %d, %Y - %I:%M %p"
|
||||
local filename = string.format("JRNL-%s.md", timestamp)
|
||||
local filename = "JRNL-" .. timestamp .. ".md"
|
||||
|
||||
ensure_dir(journal_dir)
|
||||
local path = journal_dir .. "/" .. filename
|
||||
@ -51,86 +49,103 @@ local function new_journal_note()
|
||||
})
|
||||
if ok then
|
||||
vim.cmd.edit(path)
|
||||
-- Position cursor after the title for immediate writing
|
||||
vim.cmd "normal! Go"
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("JrnlNew", new_journal_note, { desc = "Create a new journal entry and open it" })
|
||||
|
||||
-- ---------- :JrnlCompile ----------
|
||||
-- Compiles all JRNL-*.md files into a single PDF using pandoc
|
||||
local function compile_journal()
|
||||
local config_file = journal_dir .. "/journal_config.txt"
|
||||
-- Change to journal directory
|
||||
local original_dir = vim.fn.getcwd()
|
||||
vim.cmd("cd " .. vim.fn.fnameescape(journal_dir))
|
||||
|
||||
-- Create default config if it doesn't exist
|
||||
-- Find journal files using simple glob in current directory
|
||||
local journal_files = vim.fn.glob("JRNL-*.md", false, true)
|
||||
|
||||
if #journal_files == 0 then
|
||||
vim.notify("No journal entries found", vim.log.levels.WARN)
|
||||
vim.cmd("cd " .. vim.fn.fnameescape(original_dir))
|
||||
return
|
||||
end
|
||||
|
||||
-- Read config
|
||||
local config_file = "journal_config.txt"
|
||||
if vim.fn.filereadable(config_file) == 0 then
|
||||
local default_config = {
|
||||
"# Journal Compilation Config",
|
||||
"# Edit this file to customize your journal PDF output",
|
||||
"",
|
||||
"# Pandoc options (one per line, without leading dashes)",
|
||||
"# Journal Config",
|
||||
"pdf-engine=xelatex",
|
||||
"V geometry:margin=1in",
|
||||
"V mainfont=Times New Roman",
|
||||
"V fontsize=11pt",
|
||||
"toc",
|
||||
"toc-depth=2",
|
||||
"",
|
||||
"# Title page info",
|
||||
"V title=My Journal",
|
||||
"V author=Dane",
|
||||
"V date=" .. os.date "%B %Y",
|
||||
}
|
||||
|
||||
local fh = io.open(config_file, "w")
|
||||
if fh then
|
||||
fh:write(table.concat(default_config, "\n"))
|
||||
fh:close()
|
||||
vim.notify("Created default journal config at: " .. config_file, vim.log.levels.INFO)
|
||||
vim.notify("Created journal config file", vim.log.levels.INFO)
|
||||
end
|
||||
end
|
||||
|
||||
-- Read config file
|
||||
local config_lines = {}
|
||||
-- Parse config
|
||||
local config_args = {}
|
||||
local fh = io.open(config_file, "r")
|
||||
if fh then
|
||||
for line in fh:lines() do
|
||||
local trimmed = line:match "^%s*(.-)%s*$" -- trim whitespace
|
||||
local trimmed = line:match "^%s*(.-)%s*$"
|
||||
if trimmed ~= "" and not trimmed:match "^#" then
|
||||
table.insert(config_lines, "--" .. trimmed)
|
||||
if trimmed:match "^V " then
|
||||
local var_content = trimmed:match "^V (.+)"
|
||||
table.insert(config_args, "-V")
|
||||
table.insert(config_args, var_content)
|
||||
else
|
||||
table.insert(config_args, "--" .. trimmed)
|
||||
end
|
||||
end
|
||||
end
|
||||
fh:close()
|
||||
end
|
||||
|
||||
-- Build pandoc command
|
||||
local config_args = table.concat(config_lines, " ")
|
||||
local output_file = journal_dir .. "/compiled_journal.pdf"
|
||||
print(journal_dir)
|
||||
local cmd = string.format(
|
||||
"cd '%s' && find . -name 'JRNL-*.md' | sort | xargs cat | pandoc %s -o '%s'",
|
||||
journal_dir,
|
||||
config_args,
|
||||
output_file
|
||||
)
|
||||
-- Sort files
|
||||
table.sort(journal_files)
|
||||
|
||||
vim.notify("Compiling journal entries...", vim.log.levels.INFO)
|
||||
-- Build command as table to avoid shell escaping issues
|
||||
local cmd_parts = { "pandoc" }
|
||||
|
||||
-- Run the command
|
||||
local result = vim.fn.system(cmd)
|
||||
local exit_code = vim.v.shell_error
|
||||
-- Add input files
|
||||
for _, file in ipairs(journal_files) do
|
||||
table.insert(cmd_parts, file)
|
||||
end
|
||||
|
||||
if exit_code == 0 then
|
||||
vim.notify("Journal compiled successfully: " .. output_file, vim.log.levels.INFO)
|
||||
-- Add config args
|
||||
for _, arg in ipairs(config_args) do
|
||||
table.insert(cmd_parts, arg)
|
||||
end
|
||||
|
||||
-- Add output
|
||||
table.insert(cmd_parts, "-o")
|
||||
table.insert(cmd_parts, "compiled_journal.pdf")
|
||||
|
||||
vim.notify("Compiling " .. #journal_files .. " journal entries...", vim.log.levels.INFO)
|
||||
|
||||
-- Run pandoc using vim.system (avoids shell entirely)
|
||||
local result = vim.system(cmd_parts):wait()
|
||||
|
||||
-- Return to original directory
|
||||
vim.cmd("cd " .. vim.fn.fnameescape(original_dir))
|
||||
|
||||
if result.code == 0 then
|
||||
vim.notify("Journal compiled successfully!", vim.log.levels.INFO)
|
||||
else
|
||||
vim.notify("Journal compilation failed: " .. result, vim.log.levels.ERROR)
|
||||
local error_msg = result.stderr or "Unknown error"
|
||||
vim.notify("Compilation failed: " .. error_msg, vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("JrnlCompile", compile_journal, { desc = "Compile all JRNL-*.md files into PDF" })
|
||||
vim.api.nvim_create_user_command("JrnlNew", new_journal_note, { desc = "Create new journal entry" })
|
||||
vim.api.nvim_create_user_command("JrnlCompile", compile_journal, { desc = "Compile journal to PDF" })
|
||||
|
||||
-- ---------- keymaps ----------
|
||||
-- Add to your existing keymaps section
|
||||
vim.keymap.set("n", "<leader>jn", ":JrnlNew<CR>", { desc = "Journal: New entry" })
|
||||
vim.keymap.set("n", "<leader>jc", ":JrnlCompile<CR>", { desc = "Journal: Compile to PDF" })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user