Created
November 20, 2017 16:08
-
-
Save eschnett/1b3d07b21827631827e20087cb1b8616 to your computer and use it in GitHub Desktop.
Run this as `view (long (ls "."))`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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