-
Notifications
You must be signed in to change notification settings - Fork 41
/
schemes.nix
42 lines (38 loc) · 1.19 KB
/
schemes.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{ lib, base16-schemes, ... }:
let
inherit (builtins)
readFile readDir attrNames listToAttrs stringLength substring baseNameOf
filter;
inherit (lib) schemeFromYAML;
# Borrowed from nixpkgs
removeSuffix = suffix: str:
let
sufLen = stringLength suffix;
sLen = stringLength str;
in
if sufLen <= sLen && suffix == substring (sLen - sufLen) sufLen str then
substring 0 (sLen - sufLen) str
else
str;
hasSuffix = suffix: content:
let
lenContent = stringLength content;
lenSuffix = stringLength suffix;
in
lenContent >= lenSuffix
&& substring (lenContent - lenSuffix) lenContent content == suffix;
stripYamlExtension = filename:
removeSuffix ".yml" (removeSuffix ".yaml" filename);
isYamlFile = filename:
(hasSuffix ".yml" filename) || (hasSuffix ".yaml" filename);
colorSchemeFiles = filter isYamlFile (attrNames (readDir base16-schemes));
colorSchemes = listToAttrs (map
(filename: rec {
# Scheme slug
name = stripYamlExtension (baseNameOf filename);
# Scheme contents
value = schemeFromYAML name (readFile "${base16-schemes}/${filename}");
})
colorSchemeFiles);
in
colorSchemes