Skip to content

Instantly share code, notes, and snippets.

@itayd
Created December 15, 2010 13:42
Show Gist options
  • Save itayd/741949 to your computer and use it in GitHub Desktop.
Save itayd/741949 to your computer and use it in GitHub Desktop.
xmonad grid browser
-- grid browser
-- excerpt from xmonad.hs
gridBrowse cwd' = do
refresh
cwd <- liftIO $ canonicalizePath cwd'
isdir <- liftIO $ doesDirectoryExist cwd
if isdir
then do
ls <- liftIO $ getDirectoryContents cwd >>= markdirs
let ls' = if cwd == "/" then togs ls else ("../",cwd ++ "/.."):togs ls
gridselect (buildDefaultGSConfig colorizer) ls' >>= flip whenJust gridBrowse
else do
perms <- liftIO $ getPermissions cwd
spawn $ if executable perms then cwd
else "/usr/bin/xdg-open \"" ++ cwd ++ "\""
where
togs = map (\l -> (l,cwd' ++ "/" ++ l)) . filter (not . isPrefixOf ".")
markdirs = mapM $ \l -> do
isdir <- doesDirectoryExist (cwd' ++ "/" ++ l)
return $ l ++ if isdir then "/" else ""
colorizer s b = do
c <- stringColorizer s b
return $ if last s == '/' then (fst c, "black") else c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment