Advertisement
icon_bishop

obsidian.lua

Dec 9th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. -- ~/.config/nvim/lua/plugins/obsidian.lua
  2.  
  3. -- Setup for obsidian.nvim
  4. require("obsidian").setup({
  5. workspaces = {
  6. {
  7. name = "cmcscrpt",
  8. path = "~/Documents/cmcjrny/cmcscrpt",
  9. },
  10. {
  11. name = "storybible",
  12. path = "~/Documents/cmcjrny/storybible",
  13. },
  14. {
  15. name = "notes",
  16. path = "~/Documents/cmcjrny/notes",
  17. },
  18. },
  19.  
  20. daily_notes = {
  21. folder = "notes/dailies",
  22. date_format = "%Y-%m-%d",
  23. alias_format = "%B %-d, %Y",
  24. default_tags = { "daily-notes" },
  25. template = nil -- Add template path here if using one
  26. },
  27.  
  28. completion = {
  29. nvim_cmp = true,
  30. min_chars = 2,
  31. },
  32.  
  33. log_level = vim.log.levels.INFO, -- Adjust as needed
  34.  
  35. -- Optional: Configure additional plugin dependencies
  36. dependencies = {
  37. "nvim-lua/plenary.nvim",
  38. "nvim-treesitter/nvim-treesitter",
  39. "nvim-telescope/telescope.nvim", -- Enables search and quick-switch functionality
  40. },
  41. })
  42. -- Function to create a new character file from template
  43. local function create_character_template()
  44. -- Set paths for the template and folders for each character type
  45. local template_path = vim.fn.expand("~/Documents/cmcjrny/storybible/templates/CharacterTemplate.md")
  46. local folders = {
  47. main = vim.fn.expand("~/Documents/cmcjrny/storybible/chrctrs/main/"),
  48. minor = vim.fn.expand("~/Documents/cmcjrny/storybible/chrctrs/minor/"),
  49. secondary = vim.fn.expand("~/Documents/cmcjrny/storybible/chrctrs/secondary/"),
  50. }
  51.  
  52. -- Prompt for the character type
  53. vim.ui.select({ "main", "minor", "secondary" }, { prompt = "Choose character type:" }, function(folder)
  54. if folder then
  55. local target_dir = folders[folder]
  56.  
  57. -- Prompt for the new character's filename
  58. vim.ui.input({ prompt = "Enter character name: " }, function(input)
  59. if input then
  60. -- Formulate the target path
  61. local target_path = target_dir .. input .. ".md"
  62.  
  63. -- Check if target directory exists; create it if it doesn't
  64. vim.fn.mkdir(target_dir, "p")
  65.  
  66. -- Copy the template file to the new path
  67. local result = vim.fn.system({ "cp", template_path, target_path })
  68.  
  69. -- Check for errors in the copy command
  70. if vim.v.shell_error ~= 0 then
  71. vim.notify("Error copying template: " .. result, vim.log.levels.ERROR)
  72. else
  73. -- Open the new character file in Neovim and save it
  74. vim.cmd("edit " .. target_path)
  75. vim.cmd("write")
  76. end
  77. end
  78. end)
  79. end
  80. end)
  81. end
  82.  
  83. -- Keybinding to create character file with <leader>ct
  84. vim.keymap.set("n", "<leader>ct", create_character_template, { noremap = true, silent = true })
  85.  
Tags: neovim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement