changeset 648:c5ed13440614

Set and optionally create backup and undo dirs
author zegervdv <zegervdv@me.com>
date Fri, 02 Sep 2022 07:37:49 +0200
parents 7e98d6e02819
children cc06db32b946
files .chezmoitemplates/config.vim .chezmoitemplates/init.lua
diffstat 2 files changed, 9 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/.chezmoitemplates/config.vim	Thu Sep 01 15:59:47 2022 +0200
+++ b/.chezmoitemplates/config.vim	Fri Sep 02 07:37:49 2022 +0200
@@ -4,25 +4,6 @@
 let s:windows = has('win32')
 
 
-" General Settings and options
-
-if !s:windows
-  if !isdirectory(expand(&backupdir))
-    call mkdir(expand(&backupdir), "p")
-  endif
-  if !isdirectory(expand(&directory))
-    call mkdir(expand(&directory), "p")
-  endif
-end
-
-if v:version >= 703
-  if !isdirectory(expand(&undodir))
-    call mkdir(expand(&undodir), "p")
-  endif
-endif
-
-"
-
 " Mappings
 
 
--- a/.chezmoitemplates/init.lua	Thu Sep 01 15:59:47 2022 +0200
+++ b/.chezmoitemplates/init.lua	Fri Sep 02 07:37:49 2022 +0200
@@ -770,12 +770,19 @@
 
 opt.pastetoggle = '<F2>' -- Enable paste mode
 
+local optdir = function(path)
+  local Path = require 'plenary.path'
+  local full_path = Path:new(vim.fn.stdpath 'cache' .. '/' .. path)
+  if not full_path:exists() then full_path:mkdir { parents = true } end
+  return full_path .. '//'
+end
+
 opt.undofile = true -- Persistently remember undos
 opt.undolevels = 1000
-opt.undodir = home .. '/.config/nvim/tmp/undo//'
+opt.undodir = optdir 'undo'
 opt.swapfile = false -- Disable swap files
 opt.backup = true -- Keep backups
-opt.backupdir = home .. '/.config/nvim/tmp/backup//'
+opt.backupdir = optdir 'backup'
 
 -- Files to ignore from completion
 opt.wildignore:append {