diff options
author | crupest <crupest@outlook.com> | 2023-09-08 17:57:37 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-09-15 14:39:46 +0800 |
commit | c69439461887eaa5e3d70d520d012413a876bc5e (patch) | |
tree | 43368080c48936b82a318076a4e2df3b1298d9cf /configs/nvim/lua/crupest/system/fs.lua | |
parent | e1bf2af8e57f54476c71f20513ad1d4c9e9cb770 (diff) | |
download | crupest-c69439461887eaa5e3d70d520d012413a876bc5e.tar.gz crupest-c69439461887eaa5e3d70d520d012413a876bc5e.tar.bz2 crupest-c69439461887eaa5e3d70d520d012413a876bc5e.zip |
Update nvim config. Powerful move.
Diffstat (limited to 'configs/nvim/lua/crupest/system/fs.lua')
-rw-r--r-- | configs/nvim/lua/crupest/system/fs.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/configs/nvim/lua/crupest/system/fs.lua b/configs/nvim/lua/crupest/system/fs.lua new file mode 100644 index 0000000..25ce02c --- /dev/null +++ b/configs/nvim/lua/crupest/system/fs.lua @@ -0,0 +1,58 @@ +local function exist(path) + return vim.uv.fs_stat(path) +end + +local function isfile(path) + local s = vim.uv.fs_stat(path) + if not s then return false end + return s.type == "file" +end + +local function isdir(path) + local s = vim.uv.fs_stat(path) + if not s then return false end + return s.type == "directory" +end + +local function mkdir(dir) + local parents = {} + require("crupest/system").walk_up(dir, function(p) + table.insert(parents, 1, p) + end) + + for _, v in ipairs(parents) do + if exist(v) and not isdir(v) then + vim.notify(v.." is not a dir. Can't make dir "..dir, vim.log.levels.ERROR) + return + end + if not exist(v) then + vim.notify("Creating dir "..v) + assert(vim.uv.fs_mkdir(v, 504)) -- mode = 0770 + end + end +end + +local function copy(old, new) + mkdir(vim.fn.fnamemodify(new, ":p:h")) + assert(vim.uv.fs_copyfile(old, new)) +end + +local function remove(path) + assert(vim.uv.fs_unlink(path)) +end + +local function move(old, new) + mkdir(vim.fn.fnamemodify(new, ":p:h")) + assert(vim.uv.fs_rename(old, new)) +end + +return { + exist = exist, + isfile = isfile, + isdir = isdir, + mkdir = mkdir, + copy = copy, + remove = remove, + move = move +} + |