aboutsummaryrefslogtreecommitdiff
path: root/configs/nvim/lua/crupest/utils/fs.lua
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-09-07 03:09:26 +0800
committercrupest <crupest@outlook.com>2024-09-07 03:09:26 +0800
commitec32328466544dca1d2b7db759ea119571080e10 (patch)
tree003c295cfd5b2615e566a07db76478aad427b906 /configs/nvim/lua/crupest/utils/fs.lua
parent719e7980180a83d2f23442641bbecc7c8c6f97ec (diff)
downloadcrupest-ec32328466544dca1d2b7db759ea119571080e10.tar.gz
crupest-ec32328466544dca1d2b7db759ea119571080e10.tar.bz2
crupest-ec32328466544dca1d2b7db759ea119571080e10.zip
config(nvim): create new file structure.
Diffstat (limited to 'configs/nvim/lua/crupest/utils/fs.lua')
-rw-r--r--configs/nvim/lua/crupest/utils/fs.lua101
1 files changed, 0 insertions, 101 deletions
diff --git a/configs/nvim/lua/crupest/utils/fs.lua b/configs/nvim/lua/crupest/utils/fs.lua
deleted file mode 100644
index d34c2f6..0000000
--- a/configs/nvim/lua/crupest/utils/fs.lua
+++ /dev/null
@@ -1,101 +0,0 @@
-local function clean_path(path)
- if path == "/" then return path end
- path = string.gsub(path, "[/\\]+", "/")
- if string.sub(path, string.len(path)) == '/' then
- path = string.sub(path, 1, string.len(path) - 1)
- end
- return path
-end
-
-local function full_path(name)
- local path = vim.fn.fnamemodify(name, ":p")
- return clean_path(path)
-end
-
-local function escape_space(str)
- return (string.gsub(str, " ", "\\ "))
-end
-
-local function path_get_dir(path)
- return full_path(vim.fn.fnamemodify(clean_path(path), ":h"))
-end
-
-local function walk_up(path, func)
- local current_path = full_path(path)
- while true do
- local result = func(current_path)
- if result ~= nil then
- return result
- end
- local new_path = path_get_dir(current_path)
- if new_path == current_path then
- break
- end
- current_path = new_path
- end
- return nil
-end
-
-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 = {}
-
- 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(path_get_dir(new))
- 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(path_get_dir(new))
- assert(vim.uv.fs_rename(old, new))
-end
-
-return {
- clean_path = clean_path,
- full_path = full_path,
- escape_space = escape_space,
- path_get_dir = path_get_dir,
- walk_up = walk_up,
- exist = exist,
- isfile = isfile,
- isdir = isdir,
- mkdir = mkdir,
- copy = copy,
- remove = remove,
- move = move
-}