aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authordimchee <dimchee90@gmail.com>2023-03-01 20:11:16 +0100
committerdimchee <dimchee90@gmail.com>2023-03-01 20:11:16 +0100
commit27225e665bb624b94f841204f8c09f85c634dcd4 (patch)
treeff678029ff0e5b395fc6d0033beb7e27b27fc11f /lua
parentdocs(readme): updated spacing (diff)
refactor: shell ls to vim.fs.dir
Diffstat (limited to 'lua')
-rw-r--r--lua/pets/utils.lua23
1 files changed, 6 insertions, 17 deletions
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/"