]> git.r.bdr.sh - rbdr/dotfiles/commitdiff
Add brain config
authorRuben Beltran del Rio <redacted>
Thu, 29 Feb 2024 21:44:10 +0000 (22:44 +0100)
committerRuben Beltran del Rio <redacted>
Thu, 29 Feb 2024 21:44:10 +0000 (22:44 +0100)
config/nvim/init.lua
config/nvim/lazy-lock.json
config/nvim/lua/brain.lua [new file with mode: 0644]
config/nvim/lua/plugins.lua

index 26b7156b14ca1eeecae4995a5bfdbcf7e99a9d31..ac926b38a19270f06ccbfc67ac19beb341df43bd 100644 (file)
@@ -81,6 +81,9 @@ pcall(require, 'init_local')
 vim.keymap.set("n", "<c-P>",
   "<cmd>lua require('fzf-lua').files({ fzf_opts = {} })<CR>", { silent = true })
 
+-- Toggle Autosave
+vim.api.nvim_set_keymap('n', '<leader>n', ':ASToggle<CR>', {})
+
 -- Svelte Config
 vim.g.vim_svelte_plugin_use_typescript = true
 
@@ -99,3 +102,4 @@ require('plugins')
 require('treesitter_config')
 require('lsp')
 require('dap_config')
+require('brain')
index 610d03f4f703026d9c09c91f971894ab58ef494a..83dd80b98f2129ea3f0db4009655d19f1f4b685b 100644 (file)
@@ -1,5 +1,6 @@
 {
   "LargeFile": { "branch": "master", "commit": "3941a37b2b0288524300348a39521a46539bf9f6" },
+  "auto-save.nvim": { "branch": "main", "commit": "979b6c82f60cfa80f4cf437d77446d0ded0addf0" },
   "coq_nvim": { "branch": "coq", "commit": "76fa95ea445b3d33968ff60bc6a3e2e8e0132551" },
   "fzf-lua": { "branch": "main", "commit": "d68d1cfde9bf82061dfdfe35b83fb8636e03766d" },
   "gemini.vim": { "branch": "master", "commit": "c9efb59c97b71c28d4678c79fd21fbdd3a69d196" },
diff --git a/config/nvim/lua/brain.lua b/config/nvim/lua/brain.lua
new file mode 100644 (file)
index 0000000..4dfd231
--- /dev/null
@@ -0,0 +1,63 @@
+local brain_home = os.getenv('HOME') .. '/brain'
+local templates_path = brain_home .. '/1 periodic/99 templates'
+
+local function load_template(template_name)
+  local template_path = brain_home .. templates_path .. '/' .. template_name
+
+  local template_file = io.open(template_path, "r")
+  if not template_file then
+      print("Template file not found")
+      return
+  end
+  local content = template_file:read("*a")
+  template_file:close()
+end
+
+local function open_or_create_from_template(template_name, file)
+  local journal_file = io.open(file, "r")
+  if not journal_file then
+    local template_contents = load_template(template_name)
+
+    journal_file = io.open(file, "w")
+    journal_file:write(template_contents)
+    journal_file:close()
+  end
+  vim.cmd("edit " .. file)
+end
+
+function open_daily_note()
+    local filename_format = os.date('%Y-%m-%d')
+    local template_name = '001 daily.md'
+
+    local daily_note = brain_home .. "/1 periodic/01 journal/" .. filename_format .. ".md"
+    open_or_create_from_template(template_name, daily_note)
+end
+
+function open_weekly_note()
+    local filename_format = os.date('%Y-w%V')
+    local template_name = '002 weekly.md'
+
+    local weekly_note = brain_home .. "/1 periodic/02 weeks/" .. filename_format .. ".md"
+    open_or_create_from_template(template_name, weekly_note)
+end
+
+function toggle_task()
+    local line_num = vim.api.nvim_win_get_cursor(0)[1]
+    local line = vim.api.nvim_get_current_line()
+
+    local unchecked_pattern = '^%s*%- %[ %]'
+    local checked_pattern = '^%s*%- %[x%]'
+
+    if line:match(unchecked_pattern) then
+        line = line:gsub(unchecked_pattern, '- [x]', 1)
+    elseif line:match(checked_pattern) then
+        line = line:gsub(checked_pattern, '- [ ]', 1)
+    end
+
+    vim.api.nvim_buf_set_lines(0, line_num - 1, line_num, false, {line})
+end
+
+-- Keybinds
+vim.api.nvim_set_keymap('n', '<leader>od', '<cmd>lua open_daily_note()<CR>', { noremap = true, silent = true })
+vim.api.nvim_set_keymap('n', '<leader>ow', '<cmd>lua open_weekly_note()<CR>', { noremap = true, silent = true })
+vim.api.nvim_set_keymap('n', '<leader>t', '<cmd>lua toggle_task()<CR>', { noremap = true, silent = true })
index 24154d995886c17104b0c9acc11bfe70e58964c2..20cb89ec27a2a60650a44ce2f908ded4a0429dfc 100644 (file)
@@ -57,6 +57,7 @@ require('lazy').setup({
   'tpope/vim-endwise',
   'rstacruz/vim-closer',
   'michaeljsmith/vim-indent-object',
+  'Pocco81/auto-save.nvim',
 
   -- Treesitter
   'nvim-treesitter/nvim-treesitter',