os.path.expanduser analogue

On the whole, the filepath package does an excellent job of providing basic path manipulation tools, one weakness is the inability to resolve "~/..." style POSIX paths. Python implements this with os.path.expanduser. Perhaps a similar function might be helpful in filepath? Cheers, - Ben Possible (but untested) implementation expandUser :: FilePath -> IO FilePath expandUser p = if "~/" `isPrefixOf` p then do u <- getLoginName return $ u ++ drop 2 p else return p

On Sun, Nov 20, 2011 at 20:36, Ben Gamari
expandUser :: FilePath -> IO FilePath expandUser p = if "~/" `isPrefixOf` p then do u <- getLoginName return $ u ++ drop 2 p else return p
expandUser "~" = fmap homeDirectory getLoginName expandUser ('~':'/':p) = getLoginName >>= fmap ((++ p) . homeDirectory) getUserEntryForName expandUser ('~':up) = let (u,p) = break (== '/') up in fmap ((++ (drop 1 p)) . homeDirectory (getUserEntryForName u) expandUser p = p Although arguably there should be some error checking. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

On Sun, 20 Nov 2011 21:02:30 -0500, Brandon Allbery
On Sun, Nov 20, 2011 at 20:36, Ben Gamari
wrote: [Snip] Although arguably there should be some error checking.
Thanks for the improved implementation. I should have re-read my code before sending as it wasn't even close to correct. Cheers, - Ben
participants (2)
-
Ben Gamari
-
Brandon Allbery