about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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 = {