Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@eschnett
Created November 20, 2017 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eschnett/1b3d07b21827631827e20087cb1b8616 to your computer and use it in GitHub Desktop.
Save eschnett/1b3d07b21827631827e20087cb1b8616 to your computer and use it in GitHub Desktop.
Run this as `view (long (ls "."))`
{-# LANGUAGE OverloadedStrings #-}
module TurtleLong (long) where
import qualified Data.Text as T
import Prelude hiding (FilePath)
import Data.Time.Clock.POSIX
import Turtle
showFileType :: FileStatus -> Text
showFileType st
| isBlockDevice st = "b"
| isCharacterDevice st = "c"
| isDirectory st = "d"
| isNamedPipe st = "|"
| isRegularFile st = "-"
| isSocket st = "="
| isSymbolicLink st = "s"
| otherwise = "?"
showFileSize :: FileStatus -> Text
showFileSize st =
T.justifyRight 10 ' ' $ T.pack (show (fileSize st))
showFileTime :: FileStatus -> Text
showFileTime st =
format utc (posixSecondsToUTCTime (modificationTime st))
showFileStatus :: FileStatus -> Text
showFileStatus st =
T.unwords [showFileType st, showFileSize st, showFileTime st]
-- TODO: quote spaces and newlines
showFileName :: FilePath -> Text
showFileName p =
format fp p
showFilePathLong :: MonadIO io => FilePath -> io Line
showFilePathLong p = do
st <- stat p
return $ unsafeTextToLine $ T.unwords [showFileStatus st, showFileName p]
long :: Shell FilePath -> Shell Line
long ps = join $ fmap showFilePathLong ps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment