summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2017-05-31 15:28:03 +0200
committerFélix Sipma <felix.sipma@no-log.org>2017-05-31 15:28:03 +0200
commit53a20e32f8b57afa51d68f5790208640b901af86 (patch)
tree09b0d0c70cd4508248cfcfbaeabc81b023323884
add vcard_uid_generator.hs
-rwxr-xr-xvcard_uid_generator.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/vcard_uid_generator.hs b/vcard_uid_generator.hs
new file mode 100755
index 0000000..c2722b7
--- /dev/null
+++ b/vcard_uid_generator.hs
@@ -0,0 +1,23 @@
+#!/usr/bin/env stack
+-- stack --install-ghc runghc --package turtle
+
+{-# LANGUAGE OverloadedStrings #-}
+
+import Turtle
+import qualified Control.Foldl as Fold
+import Prelude hiding (FilePath)
+
+parser :: Parser FilePath
+parser = argPath "src" "source directory containing the VCARD files"
+
+main = sh $ do
+ src <- options "A simple in-place UID generator for VCARD files" parser
+ let contacts = inshell ("rg UID --files-without-match " <> format fp src) empty
+ file <- fromText . lineToText <$> contacts
+ lines <- fold (input file) Fold.list
+ let (beginning, end) = splitAt 2 lines
+ valrand <- rand
+ let b = select (beginning ++ [valrand] ++ end)
+ output file b
+ where
+ rand = inshell "cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 36 | head -n 1 | sed -e 's/^\\(.*\\)/UID:\\1\r/'" empty