fn: Improve readability of fn.lst function arguments.
This commit is contained in:
parent
b6b22c2c22
commit
c1c5ff299e
4 changed files with 32 additions and 31 deletions
32
fn.nix
32
fn.nix
|
@ -32,31 +32,33 @@ rec {
|
|||
*/
|
||||
cwd = builtins.getEnv "PWD";
|
||||
|
||||
# lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH)
|
||||
/**
|
||||
lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH)
|
||||
*/
|
||||
lst =
|
||||
{
|
||||
p ? cwd,
|
||||
t ? "regular",
|
||||
b ? false,
|
||||
path ? cwd,
|
||||
fileType ? "regular",
|
||||
fullPath ? false,
|
||||
}:
|
||||
(lists.forEach (attrNames (filterAttrs (n: v: v == t) (readDir p))) (
|
||||
v: ((optionalString b "${p}/") + v)
|
||||
assert (builtins.isString path) || throw "Argument path needs to be a string.";
|
||||
(lists.forEach (attrNames (filterAttrs (n: v: v == fileType) (readDir path))) (
|
||||
v: ((optionalString fullPath "${path}/") + v)
|
||||
));
|
||||
lsf = p: (lst { inherit p; });
|
||||
lsf = path: (lst { inherit path; });
|
||||
lsd =
|
||||
p:
|
||||
path:
|
||||
(lst {
|
||||
inherit p;
|
||||
t = "directory";
|
||||
b = true;
|
||||
inherit path;
|
||||
fileType = "directory";
|
||||
fullPath = true;
|
||||
});
|
||||
lsfRec =
|
||||
p: b:
|
||||
path: fullPath:
|
||||
flatten (
|
||||
(map (np: lsfRec np b) (lsd p))
|
||||
(map (nextPath: lsfRec nextPath fullPath) (lsd path))
|
||||
++ (lst {
|
||||
inherit p;
|
||||
inherit b;
|
||||
inherit path fullPath;
|
||||
})
|
||||
);
|
||||
hasAttrs = aList: d: (map (a: (ifelse (isList a) (hasAttrByPath a d) (hasAttr a d))) aList);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue