X-Git-Url: https://git.r.bdr.sh/rbdr/nota.nvim/blobdiff_plain/503d09fc95a47c13141d097cf80dd243d1dce342..HEAD:/lua/util.lua diff --git a/lua/util.lua b/lua/util.lua deleted file mode 100644 index 2636e7c..0000000 --- a/lua/util.lua +++ /dev/null @@ -1,48 +0,0 @@ -------------------------------------------------------------------------------- --- Utilities shared by all modules. Categorize better if > 5 public functions -------------------------------------------------------------------------------- -local Util = {} -------------------------------------------------------------------------------- --- Internal Functions -------------------------------------------------------------------------------- -local fs = vim.loop - -local function create_directory(directory) - local stat = fs.fs_stat(directory) - if stat then - if stat.type == 'directory' then - return - else - error('Expected directory but found file at: ' .. directory) - end - else - local parent = directory:match('(.+)/[^/]*$') - if parent then - create_directory(parent) - end - local success, error = fs.fs_mkdir(directory, 493) - if not success then - error('Could not directory at: ' .. directory .. '. ' .. error) - end - end -end -------------------------------------------------------------------------------- --- Public Interface -------------------------------------------------------------------------------- -function Util.ensure_directory_exists(path) - local full_path = vim.fn.expand(path) - create_directory(path) -end - -function Util.join(...) - local separator = '/' - local paths = {...} - return table.concat(paths, separator):gsub(separator..'+', separator) -end - -function Util.directory_name(file_path) - local pattern = '(.+)/[^/]+$' - return file_path:match(pattern) -end - -return Util