aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorGiuseppe Gadola <67549788+giusgad@users.noreply.github.com>2023-03-02 11:19:04 +0100
committerGitHub <noreply@github.com>2023-03-02 11:19:04 +0100
commit3c56dcab2173914e9e51a3f7824477c1b857deaa (patch)
treeff678029ff0e5b395fc6d0033beb7e27b27fc11f /lua
parentdocs(readme): updated spacing (diff)
parentrefactor: shell ls to vim.fs.dir (diff)
chore: merge pull request #28 from dimchee/main
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/"