<div dir="ltr">On Sun, Nov 20, 2011 at 20:36, Ben Gamari <span dir="ltr"><<a href="mailto:bgamari.foss@gmail.com">bgamari.foss@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
expandUser :: FilePath -> IO FilePath<br>
expandUser p = if "~/" `isPrefixOf` p<br>
then do u <- getLoginName<br>
return $ u ++ drop 2 p<br>
else return p<br></blockquote><div><br></div><div class="gmail_quote"><div><font class="Apple-style-span" face="'courier new', monospace">expandUser "~" = fmap homeDirectory getLoginName</font></div>
</div><div><font class="Apple-style-span" face="'courier new', monospace">expandUser ('~':'/':p) = getLoginName >>= </font></div><div><font class="Apple-style-span" face="'courier new', monospace"> fmap ((++ p) . homeDirectory)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> getUserEntryForName</font></div><div><font class="Apple-style-span" face="'courier new', monospace">expandUser ('~':up) = let (u,p) = break (== '/') up</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace"> in fmap ((++ (drop 1 p)) . homeDirectory</font></div><div><font class="Apple-style-span" face="'courier new', monospace"> (getUserEntryForName u)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">expandUser p = p</font></div><div><br></div></div><div>Although arguably there should be some error checking.</div><div><br></div>-- <br>
brandon s allbery <a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a><br>wandering unix systems administrator (available) (412) 475-9364 vm/sms<br><br>
</div>