From c5bc828d5883227f10e4e422dc68557ec2e096a8 Mon Sep 17 00:00:00 2001
From: Luca Bilke <luca@bil.ke>
Date: Sat, 13 Apr 2024 22:33:29 +0200
Subject: [PATCH] set up zk properly

---
 .config/nvim/lua/custom/language.lua |  9 ++++-
 .config/nvim/lua/plugins/editor.lua  | 49 ++++++++++++++++++++++++++++
 .config/zk/config.toml               |  5 ---
 .config/zsh/.zprofile                |  1 +
 4 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/.config/nvim/lua/custom/language.lua b/.config/nvim/lua/custom/language.lua
index 376b7d17..968ff56b 100644
--- a/.config/nvim/lua/custom/language.lua
+++ b/.config/nvim/lua/custom/language.lua
@@ -38,7 +38,7 @@ M.mason_install = {
     "marksman",
     "markdownlint",
     "ruff-lsp",
-    "rust-analyzer"
+    "rust-analyzer",
 }
 
 ---@type Array<string>
@@ -160,6 +160,13 @@ M.lsp_setup = {
             end
         end)
     end,
+    -- marksman = function()
+    --     LazyVim.lsp.on_attach(function(client, _)
+    --         if client.name == "marksman" then
+    --             client.server_capabilities.hoverProvider = false
+    --         end
+    --     end)
+    -- end,
     rust_analyzer = function()
         return true
     end,
diff --git a/.config/nvim/lua/plugins/editor.lua b/.config/nvim/lua/plugins/editor.lua
index 1890cde2..d1b33bc7 100644
--- a/.config/nvim/lua/plugins/editor.lua
+++ b/.config/nvim/lua/plugins/editor.lua
@@ -1,3 +1,4 @@
+---@type LazySpec
 return {
     {
         "nvim-neo-tree/neo-tree.nvim",
@@ -17,4 +18,52 @@ return {
             },
         },
     },
+    {
+        "zk-org/zk-nvim",
+        ft = { "markdown" },
+        main = "zk",
+        dependencies = {
+            {
+                "folke/which-key.nvim",
+                optional = true,
+                opts = {
+                    defaults = {
+                        ["<leader>z"] = { name = "+zk" },
+                    },
+                },
+            },
+        },
+        opts = {
+            picker = "telescope",
+            lsp = {
+                cmd = { "zk", "lsp" },
+                name = "zk",
+                config = {
+                    on_attach = function(client)
+                        if client.name == "zk" then
+                            require("zk").cd()
+                        end
+                    end,
+                },
+                auto_attach = {
+                    enabled = true,
+                    filetypes = { "markdown" },
+                },
+            },
+        },
+        --stylua: ignore
+        keys = {
+            { "<leader>zn", function() require("zk.commands").get("ZkNew")({ title = vim.fn.input('Title: ') }) end, desc = "New Note", mode = { "n", "v" } },
+            { "<leader>znt", function() require("zk.commands").get("ZkNewFromTitleSelection")() end, desc = "Title from selection", mode = { "v" } },
+            { "<leader>znc", function() require("zk.commands").get("ZkNewFromContentSelection")({ title = vim.fn.input('Title: ') }) end, desc = "Content from selection", mode = { "v" } },
+            { "<leader>zb", function() require("zk.commands").get("ZkBacklinks")() end, desc = "Links" },
+            { "<leader>zl", function() require("zk.commands").get("ZkLinks")() end, desc = "Backlinks" },
+            { "<leader>zx", function() require("zk.commands").get("ZkIndex")() end, desc = "Index" },
+            { "<leader>zf", function() require("zk.commands").get("ZkNotes")({ sort = { 'modified' } }) end, desc = "Find Notes" },
+            { "<leader>sz", function() require("zk.commands").get("ZkNotes")({ sort = { 'modified' } }) end, desc = "Notes" },
+            { "<leader>zt", function() require("zk.commands").get("ZkTags")() end, desc = "Find Note Tags" },
+            { "<leader>zf", function() require("zk.commands").get("ZkMatch")() end, desc = "Find Notes (Match Selection)", mode = { "v" } },
+            { "<leader>zi", function() require("zk.commands").get("ZkInsertLinkAtSelection")() end, desc = "Insert Link", mode = { "n", "v" } },
+        },
+    },
 }
diff --git a/.config/zk/config.toml b/.config/zk/config.toml
index b2f86803..172aa136 100644
--- a/.config/zk/config.toml
+++ b/.config/zk/config.toml
@@ -1,10 +1,5 @@
 [notebook]
 dir = "~/Documents/notes"
 
-[note]
-language = "en"
-filename = "{{slug title}}-{{id}}"
-extension = "md"
-
 [tool]
 fzf-preview = "glow -s '$XDG_CONFIG_HOME/glow/style.json' {-1}"
diff --git a/.config/zsh/.zprofile b/.config/zsh/.zprofile
index 2caa32de..b1ff9354 100644
--- a/.config/zsh/.zprofile
+++ b/.config/zsh/.zprofile
@@ -120,6 +120,7 @@ export RUSTUP_HOME="$XDG_DATA_HOME/rustup"
 export PYTHONSTARTUP="/etc/python/pythonrc"
 export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
 export XBPS_DISTDIR="$XDG_DOCUMENTS_DIR/dev/desktop/void-packages"
+export ZK_NOTEBOOK_DIR="$XDG_DOCUMENTS_DIR/notes"
 
 localpath="$(find -L ~/.local/bin -type d -printf %p: | sed 's/.$//')"
 fpath=($XDG_CONFIG_HOME/zsh/completions $fpath)