hcdu/app/Main.hs
2023-10-13 15:54:57 +02:00

28 lines
986 B
Haskell

module Main where
import System.Posix.Directory ( getWorkingDirectory )
import System.Directory
( pathIsSymbolicLink, doesFileExist, getFileSize, doesDirectoryExist )
import Data.Functor ( (<&>) )
import Control.Monad ( filterM )
import System.Directory.Extra ( listContents )
import Brick
listNonSymFiles :: FilePath -> IO [FilePath]
listNonSymFiles dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesFileExist =<< listContents dir
listNonSymDirectories :: FilePath -> IO [FilePath]
listNonSymDirectories dir = filterM (fmap not . pathIsSymbolicLink) =<< filterM doesDirectoryExist =<< listContents dir
getSizeSubpaths :: FilePath -> IO [(FilePath, Integer)]
getSizeSubpaths x = do
sub <- listNonSymDirectories x
subby <- mapM (\y -> (y,) . sum . map snd <$> getSizeSubpaths y) sub
local <- listNonSymFiles x >>= (\y -> mapM getFileSize y <&> zip y)
return $ local ++ subby
main :: IO ()
main = do
a <- getWorkingDirectory
print =<< getSizeSubpaths a