Skip to content

Instantly share code, notes, and snippets.

@joelmccracken
Created April 26, 2017 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelmccracken/b57f9b04263d56ee5ab955ac3ae39450 to your computer and use it in GitHub Desktop.
Save joelmccracken/b57f9b04263d56ee5ab955ac3ae39450 to your computer and use it in GitHub Desktop.
random haskell snippets, mostly putzing with turtle, gpg, tar, etc
_tar <- tar
stdout _tar
putStrLn $ (show r)
stdout $ inproc "gpg" ["--passphrase-fd", Data.Text.pack (show r), "--symmetric", "--batch", "--output", "encrypted.gpg"] _tar
proc "gpg" ["--passphrase", "helloworld", "--symmetric", "--batch", "--output", "encrypted.gpg"] _tar
x <- tar
y <- x
case y of
ExitSuccess -> return ()
ExitFailure n -> die ("failed " <> repr n)
return ()
return ()
stdout $ inproc "tar" ["-r", "-f", "./foo.tar", Data.Text.pack (home ++ "/Files/books")] Turtle.empty
getHomeDirectory >>= putStrLn
cd "~/Projects/reddup"
main :: IO ()
main = do
(status, output) <- shellStrict "brew list --versions" Turtle.empty
putStrLn $ show $ Prelude.map (splitOn " ") $ splitOn "\n" output
import System.FilePath
tar :: IO ()
tar = do
tar -r -f ./foo.tar ~/Files/books/
(src, dest) <- options "a simple `cp` script" parser
home <- getHomeDirectory
handle <- openFile (home ++ "/haskell-backup.hsd") ReadMode
contents <- hGetContents handle
putStrLn $ show ((read contents)::[BackupConfigOption])
(r, w) <- createPipe
fdWrite w "HITHERE\n"
closeFd w
home <- getHomeDirectory
shell (
intercalate " "
[
"tar", "-c", Data.Text.pack (home ++ "/Files/books"),
"|",
"gpg",
"--passphrase-fd", Data.Text.pack (show r),
"--symmetric", "--batch",
"--output", "encrypted.gpg"
]
) Turtle.empty
return ()
-- *Lib Turtle> b <- fold (inshell "ls " empty) countLines
-- *Lib Turtle> b
-- 8
-- *Lib Turtle>
-- *Lib Turtle> view $ fmap ((cut (char '.')) . lineToText) $ inshell "ls " empty
-- ["LICENSE"]
-- ["Setup","hs"]
-- ["app"]
-- ["reddup","cabal"]
-- ["notes","txt"]
-- ["src"]
-- ["stack","yaml"]
-- ["test"]
parser :: Parser (FilePath, FilePath)
parser = (,) <$> argPath "src" "the source file"
<*> argPath "dest" "the destination file"
let x = parse (string "??" <|> string "M") "foo" "A"
staged = A
unstaged = M
untracked = ??
data BackupConfigOption =
Directory String
deriving (Show, Read)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment