dope icon indicating copy to clipboard operation
dope copied to clipboard

use XDG based directory

Open twnaing opened this issue 3 years ago • 3 comments

I see $HOME/.cache are used instead of XDG based directory. (e.g. https://github.com/glepnir/cosynvim/blob/main/lua/core/init.lua#L6)

local home = os.getenv('HOME')

How about cosynvim using vim.fn.stdpath?

twnaing avatar Sep 14 '22 15:09 twnaing

can be support

glepnir avatar Sep 14 '22 15:09 glepnir

I made the following changes and I think it is using XDG based directory now.

diff --git a/lua/core/init.lua b/lua/core/init.lua
index a1cf392..9f58c9a 100644
--- a/lua/core/init.lua
+++ b/lua/core/init.lua
@@ -2,19 +2,18 @@
 -- date: 2022-07-02
 -- License: MIT
 
-local vim = vim
-local home = os.getenv('HOME')
+-- local vim = vim
 -- remove check is windows because I only use mac or linux
-local cache_dir = home .. '/.cache/nvim/'
+local cache_dir = vim.fn.stdpath "cache"
 
 -- Create cache dir and subs dir
 local createdir = function()
   local data_dir = {
-    cache_dir .. 'backup',
-    cache_dir .. 'session',
-    cache_dir .. 'swap',
-    cache_dir .. 'tags',
-    cache_dir .. 'undo',
+    cache_dir .. '/backup',
+    cache_dir .. '/session',
+    cache_dir .. '/swap',
+    cache_dir .. '/tags',
+    cache_dir .. '/undo',
   }
   -- There only check once that If cache_dir exists
   -- Then I don't want to check subs dir exists
diff --git a/lua/core/options.lua b/lua/core/options.lua
index 3a48c8b..a13242f 100644
--- a/lua/core/options.lua
+++ b/lua/core/options.lua
@@ -1,7 +1,7 @@
 -- author: glepnr https://github.com/glepnir
 -- date: 2022-07-02
 -- License: MIT
-local cache_dir = os.getenv('HOME') .. '/.cache/nvim/'
+local cache_dir = vim.fn.stdpath "cache"
 
 vim.opt.termguicolors = true
 vim.opt.mouse = 'nv'
@@ -21,11 +21,11 @@ vim.opt.wildignore =
 vim.opt.backup = false
 vim.opt.writebackup = false
 vim.opt.swapfile = false
-vim.opt.directory = cache_dir .. 'swag/'
-vim.opt.undodir = cache_dir .. 'undo/'
-vim.opt.backupdir = cache_dir .. 'backup/'
-vim.opt.viewdir = cache_dir .. 'view/'
-vim.opt.spellfile = cache_dir .. 'spell/en.uft-8.add'
+vim.opt.directory = cache_dir .. '/swag/'
+vim.opt.undodir = cache_dir .. '/undo/'
+vim.opt.backupdir = cache_dir .. '/backup/'
+vim.opt.viewdir = cache_dir .. '/view/'
+vim.opt.spellfile = cache_dir .. '/spell/en.uft-8.add'
 vim.opt.history = 2000
 vim.opt.shada = "!,'300,<50,@100,s10,h"
 vim.opt.backupskip = '/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/*,/private/var/*,.vault.vim'
diff --git a/lua/modules/ui/config.lua b/lua/modules/ui/config.lua
index d5453a5..7657d8f 100644
--- a/lua/modules/ui/config.lua
+++ b/lua/modules/ui/config.lua
@@ -13,11 +13,10 @@ function config.galaxyline()
 end
 
 function config.dashboard()
-  local home = os.getenv('HOME')
   local db = require('dashboard')
-  db.session_directory = home .. '/.cache/nvim/session'
+  db.session_directory = vim.fn.stdpath("cache") .. '/session'
   db.preview_command = 'cat | lolcat -F 0.3'
-  db.preview_file_path = home .. '/.config/nvim/static/neovim.cat'
+  db.preview_file_path = vim.fn.stdpath("config") .. '/static/neovim.cat'
   db.preview_file_height = 12
   db.preview_file_width = 80
   db.custom_center = {

twnaing avatar Sep 14 '22 18:09 twnaing

can use a const value for this right ?

glepnir avatar Sep 14 '22 20:09 glepnir