1import qualified Streamly.Prelude as S
2import qualified Streamly.Fold as FL
3import qualified Streamly.Memory.Array as A
4import qualified Streamly.FileSystem.File as File
7import System.Environment (getArgs)
9cat :: FilePath -> IO ()
10cat src = File.writeArrays "/dev/stdout" $ File.readArraysOf (256*1024) src
12cp :: FilePath -> FilePath -> IO ()
13cp src dst = File.writeArrays dst $ File.readArraysOf (256*1024) src
15append :: FilePath -> FilePath -> IO ()
16append src dst = File.appendArrays dst $ File.readArraysOf (256*1024) src
18ord' :: Num a => Char -> a
19ord' = (fromIntegral . ord)
21wcl :: FilePath -> IO ()
22wcl src = print =<< (S.length
23 $ FL.splitSuffixBy (== ord' '\n') FL.drain
26grepc :: String -> FilePath -> IO ()
27grepc pat src = print . (subtract 1) =<< (S.length
28 $ FL.splitOn (A.fromList (map ord' pat)) FL.drain
31avgll :: FilePath -> IO ()
32avgll src = print =<< (FL.foldl' avg
33 $ FL.splitSuffixBy (== ord' '\n') FL.length
35 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
36 toDouble = fmap (fromIntegral :: Int -> Double)
38llhisto :: FilePath -> IO ()
39llhisto src = print =<< (FL.foldl' (FL.classify FL.length)
41 $ FL.splitSuffixBy (== ord' '\n') FL.length
44 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)
48 src <- fmap head getArgs
50 putStrLn "cat" >> cat src -- Unix cat program
51 putStr "wcl " >> wcl src -- Unix wc -l program
52 putStr "grepc " >> grepc "aaaa" src -- Unix grep -c program
53 putStr "avgll " >> avgll src -- get average line length
54 putStr "llhisto " >> llhisto src -- get line length histogram
55 putStr "cp " >> cp src "dst-xyz.txt" -- Unix cp program
56 putStr "append " >> append src "dst-xyz.txt" -- Appending to file
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list