summaryrefslogtreecommitdiffstats
path: root/4lib/tv/default.nix
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-07-11 19:44:49 +0200
committertv <tv@shackspace.de>2015-07-11 19:44:49 +0200
commitbd65d2be622369d4f4b55a1d5e64aedf58506189 (patch)
tree22ddca93839a9cb9efb03fcc807dc12b1b9ea8a8 /4lib/tv/default.nix
parent2bc5c58d85990e483af8fde57ed5f2442351b69c (diff)
parentd213df5c00d3073d2f3bc09471fce466153df881 (diff)
Merge branch 'next'
Diffstat (limited to '4lib/tv/default.nix')
-rw-r--r--4lib/tv/default.nix62
1 files changed, 62 insertions, 0 deletions
diff --git a/4lib/tv/default.nix b/4lib/tv/default.nix
new file mode 100644
index 000000000..164a6a1aa
--- /dev/null
+++ b/4lib/tv/default.nix
@@ -0,0 +1,62 @@
+{ lib, pkgs, ... }:
+
+with builtins;
+
+let
+ inherit (lib) mapAttrs stringAsChars;
+in
+
+rec {
+ git = import ./git.nix {
+ lib = lib // {
+ inherit addNames;
+ };
+ inherit pkgs;
+ };
+
+ addName = name: set:
+ set // { inherit name; };
+
+ addNames = mapAttrs addName;
+
+
+ # "7.4.335" -> "74"
+ majmin = with lib; x : concatStrings (take 2 (splitString "." x));
+
+
+ concat = xs :
+ if xs == []
+ then ""
+ else head xs + concat (tail xs)
+ ;
+
+ flip = f : x : y : f y x;
+
+ # isSuffixOf :: String -> String -> Bool
+ isSuffixOf =
+ s : xs :
+ let
+ sn = stringLength s;
+ xsn = stringLength xs;
+ in
+ xsn >= sn && substring (xsn - sn) sn xs == s ;
+
+ removeSuffix =
+ s : xs : substring 0 (stringLength xs - stringLength s) xs;
+
+ # setMap :: (String -> a -> b) -> Set String a -> [b]
+ #setMap = f: xs: map (k : f k (getAttr k xs)) (attrNames xs);
+
+ # setToList :: Set k a -> [a]
+ #setToList = setMap (_: v: v);
+
+ shell-escape =
+ let
+ isSafeChar = c: match "[-./0-9_a-zA-Z]" c != null;
+ in
+ stringAsChars (c:
+ if isSafeChar c then c
+ else if c == "\n" then "'\n'"
+ else "\\${c}");
+
+}