From d341d4d9e837f353af51a32d55adfd03225f5b37 Mon Sep 17 00:00:00 2001 From: Soispha Date: Tue, 29 Aug 2023 21:01:58 +0200 Subject: Feat(hm/conf/nvim/autocmds): Add mkdir autocmd --- hm/soispha/conf/nvim/autocmds/default.nix | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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,8 +6,33 @@ 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(':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 = ["*"]; -- cgit 1.4.1