about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-08-29 21:01:58 +0200
committerSoispha <soispha@vhack.eu>2023-08-29 21:02:41 +0200
commitd341d4d9e837f353af51a32d55adfd03225f5b37 (patch)
tree3d976c22234abc77091de6175e3ac731bf090107
parentFeat(hm/conf/nvim/plgs/ltex_extra): Init (diff)
downloadnixos-config-d341d4d9e837f353af51a32d55adfd03225f5b37.zip
Feat(hm/conf/nvim/autocmds): Add mkdir autocmd
-rw-r--r--hm/soispha/conf/nvim/autocmds/default.nix25
1 files changed, 25 insertions, 0 deletions
diff --git a/hm/soispha/conf/nvim/autocmds/default.nix b/hm/soispha/conf/nvim/autocmds/default.nix
index cb0311fb..005cc038 100644
--- a/hm/soispha/conf/nvim/autocmds/default.nix
+++ b/hm/soispha/conf/nvim/autocmds/default.nix
@@ -6,9 +6,34 @@
       numbertoggle = {clear = true;};
       coloroverride = {clear = true;};
       highlight_on_yank = {clear = true;};
+      create_dir = {clear = true;};
     };
     autoCmd = [
       {
+        # Taken from: https://github.com/jghauser/mkdir.nvim
+        event = ["BufWritePre"];
+        pattern = ["*"];
+        callback = {
+          __raw = ''
+            function()
+              -- Get current filename, get full path (:p) and leave only the head (:h)
+              local dir = vim.fn.expand('<afile>:p:h')
+
+              -- This handles URLs using netrw. See ':help netrw-transparent' for details.
+              if dir:find('%l+://') == 1 then
+                return
+              end
+
+              if vim.fn.isdirectory(dir) == 0 then
+                vim.fn.mkdir(dir, 'p')
+              end
+            end
+          '';
+        };
+        group = "create_dir";
+        description = "Create the directory of the target file on write";
+      }
+      {
         event = ["TextYankPost"];
         pattern = ["*"];
         callback = {