diff options
Diffstat (limited to '.config/awesome/quarrel/fs.lua')
-rw-r--r-- | .config/awesome/quarrel/fs.lua | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/.config/awesome/quarrel/fs.lua b/.config/awesome/quarrel/fs.lua index 89a1bc6..502f189 100644 --- a/.config/awesome/quarrel/fs.lua +++ b/.config/awesome/quarrel/fs.lua @@ -1,7 +1,12 @@ -local GFile = require "lgi".Gio.File +local GFile = require("lgi").Gio.File +---@class QuarrelFs local qfs = {} +--- Read a file with the specified format (or "a") and close the file +---@param path string +---@param format openmode +---@return any function qfs.read(path, format) local f = assert(io.open(path, "r")) local c = f:read(format or "a") @@ -9,13 +14,23 @@ function qfs.read(path, format) return c end +--- List files in a directory +---@param path string +---@param absolute boolean? +---@return table function qfs.ls_files(path, absolute) local files = GFile.new_for_path(path):enumerate_children("standard::*", 0) local files_filtered = {} - if not files then return {} end + if not files then + return {} + end - for file in function() return files:next_file() end do + for file in + function() + return files:next_file() + end + do if file:get_file_type() == "REGULAR" then local file_name = file:get_display_name() file_name = absolute and (path:gsub("[/]*$", "") .. "/" .. file_name) or file_name |