diff options
author | Gregory Anders <greg@gpanders.com> | 2022-05-15 20:10:12 -0600 |
---|---|---|
committer | Gregory Anders <greg@gpanders.com> | 2022-05-31 13:04:41 -0600 |
commit | 2a62bec37ced51678ff914700d7165605d5a0d53 (patch) | |
tree | a28b0a4318142aee3acceccd3a56cacf94b8b79b /runtime/lua/vim/fs.lua | |
parent | b740709431f5e68dac5238d455f9f86d5a564f36 (diff) | |
download | rneovim-2a62bec37ced51678ff914700d7165605d5a0d53.tar.gz rneovim-2a62bec37ced51678ff914700d7165605d5a0d53.tar.bz2 rneovim-2a62bec37ced51678ff914700d7165605d5a0d53.zip |
feat(fs): add vim.fs.dir()
This function is modeled after the path.dir() function from Penlight and
the luafilesystem module.
Diffstat (limited to 'runtime/lua/vim/fs.lua')
-rw-r--r-- | runtime/lua/vim/fs.lua | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/runtime/lua/vim/fs.lua b/runtime/lua/vim/fs.lua index 29ce394a38..c28b06536b 100644 --- a/runtime/lua/vim/fs.lua +++ b/runtime/lua/vim/fs.lua @@ -48,4 +48,17 @@ function M.basename(file) return vim.fn.fnamemodify(file, ':t') end +--- Return an iterator over the files and directories located in {path} +--- +---@param path (string) An absolute or relative path to the directory to iterate +--- over +---@return Iterator over files and directories in {path}. Each iteration yields +--- two values: name and type. Each "name" is the basename of the file or +--- directory relative to {path}. Type is one of "file" or "directory". +function M.dir(path) + return function(fs) + return vim.loop.fs_scandir_next(fs) + end, vim.loop.fs_scandir(path) +end + return M |