1import qualified Streamly.Prelude as S
2import qualified Streamly.Fold as FL
3import qualified Streamly.Mem.Array as A
4import qualified Streamly.FileSystem.File as File
7import System.Environment (getArgs)
9cat :: FilePath -> IO ()
10cat src = File.writeArrays "/dev/stdout" $ File.readArraysUpto (256*1024) src
12cp :: FilePath -> FilePath -> IO ()
13cp src dst = File.writeArrays dst $ File.readArraysUpto (256*1024) src
15ord' :: Num a => Char -> a
16ord' = (fromIntegral . ord)
18wcl :: FilePath -> IO ()
19wcl src = print =<< (S.length
20 $ FL.splitSuffixBy (== ord' '\n') FL.drain
23grepc :: String -> FilePath -> IO ()
24grepc pat src = print . (subtract 1) =<< (S.length
25 $ FL.splitOn (A.fromList (map ord' pat)) FL.drain
28avgll :: FilePath -> IO ()
29avgll src = print =<< (FL.foldl' avg
30 $ FL.splitSuffixBy (== ord' '\n') FL.length
32 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
33 toDouble = fmap (fromIntegral :: Int -> Double)
35llhisto :: FilePath -> IO ()
36llhisto src = print =<< (FL.foldl' (FL.classify FL.length)
38 $ FL.splitSuffixBy (== ord' '\n') FL.length
41 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)
45 src <- fmap head getArgs
47 putStrLn "cat" >> cat src -- Unix cat program
48 putStr "wcl " >> wcl src -- Unix wc -l program
49 putStr "grepc " >> grepc "aaaa" src -- Unix grep -c program
50 putStr "avgll " >> avgll src -- get average line length
51 putStr "llhisto " >> llhisto src -- get line length histogram
52 putStr "cp " >> cp src "dst-xyz.txt" -- Unix cp program
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