Skip to content

Instantly share code, notes, and snippets.

@rethab
Created October 31, 2016 08:23
Show Gist options
  • Save rethab/b95c3a72196da0b57fc96be99da67278 to your computer and use it in GitHub Desktop.
Save rethab/b95c3a72196da0b57fc96be99da67278 to your computer and use it in GitHub Desktop.
Copy of the function mountedDevices from xmobar's Disk.hs to reproduce problem
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe (catMaybes)
import Data.List (isPrefixOf)
import System.Directory (doesFileExist, canonicalizePath)
main :: IO ()
main = mountedDevices ["mapper/home"] >>= print
mountedDevices :: [String] -> IO [(String, String)]
mountedDevices req = do
s <- B.readFile "/etc/mtab"
parse `fmap` mapM mbcanon (devs s)
where
mbcanon (d, p) = doesFileExist d >>= \e ->
if e
then Just `fmap` canon (d,p)
else return Nothing
canon (d, p) = do {d' <- canonicalizePath d; return (d', p)}
devs = filter isDev . map (firstTwo . B.words) . B.lines
parse = map undev . filter isReq . catMaybes
firstTwo (a:b:_) = (B.unpack a, B.unpack b)
firstTwo _ = ("", "")
isDev (d, _) = "/dev/" `isPrefixOf` d
isReq (d, p) = p `elem` req || drop 5 d `elem` req
undev (d, f) = (drop 5 d, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment