1import qualified Streamly.Prelude as S
2import qualified Streamly.Data.Fold as FL
3import qualified Streamly.Memory.Array as A
4import qualified Streamly.Internal.Prelude as IP
5import qualified Streamly.Internal.FileSystem.File as File
8import System.Environment (getArgs)
10cat :: FilePath -> IO ()
11cat src = File.writeArrays "/dev/stdout" $ File.toStreamArraysOf (256*1024) src
13cp :: FilePath -> FilePath -> IO ()
14cp src dst = File.writeArrays dst $ File.toStreamArraysOf (256*1024) src
16append :: FilePath -> FilePath -> IO ()
17append src dst = File.appendArrays dst $ File.toStreamArraysOf (256*1024) src
19ord' :: Num a => Char -> a
20ord' = (fromIntegral . ord)
22wcl :: FilePath -> IO ()
23wcl src = print =<< (S.length
24 $ S.splitOnSuffix (== ord' '\n') FL.drain
27grepc :: String -> FilePath -> IO ()
28grepc pat src = print . (subtract 1) =<< (S.length
29 $ IP.splitOnSeq (A.fromList (map ord' pat)) FL.drain
32avgll :: FilePath -> IO ()
33avgll src = print =<< (S.fold avg
34 $ S.splitOnSuffix (== ord' '\n') FL.length
36 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
37 toDouble = fmap (fromIntegral :: Int -> Double)
39llhisto :: FilePath -> IO ()
40llhisto src = print =<< (S.fold (FL.classify FL.length)
42 $ S.splitOnSuffix (== ord' '\n') FL.length
45 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)
49 src <- fmap head getArgs
51 putStrLn "cat" >> cat src -- Unix cat program
52 putStr "wcl " >> wcl src -- Unix wc -l program
53 putStr "grepc " >> grepc "aaaa" src -- Unix grep -c program
54 putStr "avgll " >> avgll src -- get average line length
55 putStr "llhisto " >> llhisto src -- get line length histogram
56 putStr "cp " >> cp src "dst-xyz.txt" -- Unix cp program
57 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