diff .chezmoitemplates/init.lua @ 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 eb7d12790ebe
children cc06db32b946
line wrap: on
line diff
--- 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 {