From 27225e665bb624b94f841204f8c09f85c634dcd4 Mon Sep 17 00:00:00 2001 From: dimchee Date: Wed, 1 Mar 2023 20:11:16 +0100 Subject: refactor: shell ls to vim.fs.dir --- lua/pets/utils.lua | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'lua/pets') diff --git a/lua/pets/utils.lua b/lua/pets/utils.lua index 68ea6b1..62b4913 100644 --- a/lua/pets/utils.lua +++ b/lua/pets/utils.lua @@ -1,23 +1,12 @@ local M = {} M.available_pets = {} --- list all files in a directory --- source: https://stackoverflow.com/a/11130774 -function M.listdir(directory) - local i, t, popen = 0, {}, io.popen - local pfile - pfile = popen('/bin/ls -a "' .. directory .. '"') - if pfile == nil then - error("Error getting assets for specified pet") - end - for filename in pfile:lines() do - if filename ~= "." and filename ~= ".." and not vim.endswith(filename, "sh") then - i = i + 1 - t[i] = filename - end - end - pfile:close() - return t +function M.listdir(path) + local sol = {} + for val in vim.fs.dir(path) do + table.insert(sol, val) + end + return sol end local wd = debug.getinfo(1).source:sub(2):match("(.*nvim/)") .. "media/" -- cgit v1.3-2-g11bf