1import qualified Streamly.Prelude as S
2import qualified Streamly.Data.Fold as FL
3import qualified Streamly.Memory.Array as A
4import qualified Streamly.FileSystem.Handle as FH
5import qualified System.IO as FH
6-- import qualified Streamly.FileSystem.FD as FH
7-- import qualified Streamly.String as SS
10import System.Environment (getArgs)
11import System.IO (IOMode(..), hSeek, SeekMode(..))
13cat :: FH.Handle -> IO ()
14cat src = S.runFold (FH.writeArrays FH.stdout) $ FH.readArraysOf (256*1024) src
16-- cat src = S.runFold (FH.write FH.stdout) $ FH.read src
18cp :: FH.Handle -> FH.Handle -> IO ()
19cp src dst = S.runFold (FH.writeArrays dst) $ FH.readArraysOf (256*1024) src
21-- cp src dst = S.runFold (FH.write dst) $ FH.read src
23ord' :: Num a => Char -> a
24ord' = (fromIntegral . ord)
26wcl :: FH.Handle -> IO ()
27wcl src = print =<< (S.length
32wcl src = print =<< (S.length
33 $ flip SS.foldLines FL.drain
39grepc :: String -> FH.Handle -> IO ()
40grepc pat src = print . (subtract 1) =<< (S.length
41 $ FL.splitOnSeq (A.fromList (map ord' pat)) FL.drain
45avgll :: FH.Handle -> IO ()
46avgll src = print =<< (S.runFold avg
47 $ S.splitWithSuffix (== ord' '\n') FL.length
49 where avg = (/) <$> toDouble FL.sum <*> toDouble FL.length
50 toDouble = fmap (fromIntegral :: Int -> Double)
52llhisto :: FH.Handle -> IO ()
53llhisto src = print =<< (S.runFold (FL.classify FL.length)
55 $ S.splitWithSuffix (== ord' '\n') FL.length
58 bucket n = let i = n `div` 10 in if i > 9 then (9,n) else (i,n)
62 name <- fmap head getArgs
63 src <- FH.openFile name ReadMode
64 let rewind = hSeek src AbsoluteSeek 0
66 rewind >> putStrLn "cat" >> cat src -- Unix cat program
67 rewind >> putStr "wcl " >> wcl src -- Unix wc -l program
68 -- rewind >> putStr "grepc " >> grepc "aaaa" src -- Unix grep -c program
69 rewind >> putStr "avgll " >> avgll src -- get average line length
70 rewind >> putStr "llhisto " >> llhisto src -- get line length histogram
72 dst <- FH.openFile "dst-xyz.txt" WriteMode
73 rewind >> putStr "cp " >> cp src dst -- 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