
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

On 21/11/11 02:36, Ben Gamari wrote:
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?
On windows there are folders like %UserProfile% and %ProgramFiles%. There is a function in the API, ExpandEnvironmentStrings, for expanding them. I think it makes sense that, if a function that expands "~" is added to filepath, it should do also this expanding on windows. That also means that 'expandUser' is not the right name. Twan

On Tue, Nov 22, 2011 at 09:36, Twan van Laarhoven
On 21/11/11 02:36, Ben Gamari wrote:
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?
On windows there are folders like %UserProfile% and %ProgramFiles%. There is a function in the API, ExpandEnvironmentStrings, for expanding them.
On Unix/POSIX, environment variables in file paths are typically not handled as widely as tilde expansion, or by the same facilities (for one thing, envar expansion is applicable to general strings, not just file paths; I think this is also true on Windows). This is not to say that such a facility shouldn't exist in the standard libraries, but that filepath isn't really the place for it. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
participants (3)
-
Ben Gamari
-
Brandon Allbery
-
Twan van Laarhoven