1 -------------------------------------------------------------------------------
2 -- Utilities shared by all modules. Categorize better if > 5 public functions
3 -------------------------------------------------------------------------------
5 -------------------------------------------------------------------------------
7 -------------------------------------------------------------------------------
10 local function create_directory(directory)
11 local stat = fs.fs_stat(directory)
13 if stat.type == 'directory' then
16 error('Expected directory but found file at: ' .. directory)
19 local parent = directory:match('(.+)/[^/]*$')
21 create_directory(parent)
23 local success, error = fs.fs_mkdir(directory, 493)
25 error('Could not directory at: ' .. directory .. '. ' .. error)
29 -------------------------------------------------------------------------------
31 -------------------------------------------------------------------------------
32 function Util.ensure_directory_exists(path)
33 local full_path = vim.fn.expand(path)
34 create_directory(path)
37 function Util.join(...)
40 return table.concat(paths, separator):gsub(separator..'+', separator)
43 function Util.directory_name(file_path)
44 local pattern = '(.+)/[^/]+$'
45 return file_path:match(pattern)