Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Created November 13, 2012 12:02
Show Gist options
  • Save Heimdell/4065418 to your computer and use it in GitHub Desktop.
Save Heimdell/4065418 to your computer and use it in GitHub Desktop.
Strip your spaces!
import System.Environment
import System.IO
import System.Directory
import Data.String.Utils
import Control.Monad
main = do places <- getArgs
let place = if places == []
then ["."]
else places
every place (map_dir_tree (act_on_file make_clean)
(endswith ".rb"))
where every = flip mapM_
map_dir_tree action predicate path =
do file <- getDirectoryContents path
for (every file (not . startswith ".")) $
\file -> do let fullPath = path ++ "/" ++ file
exists <- doesDirectoryExist fullPath
if exists
then dir_tree_map_ action predicate fullPath
else
when (predicate fullPath)
(action fullPath)
where for = flip mapM_
every = flip filter
act_on_file action file =
do content <- readFile file
force_reading content
packed <- action content file
writeFile file packed
force_reading = (`seq` return ()) . length
make_clean content file = do let packed = clean_teh content
when (packed /= content)
(putStrLn (file ++ "!"))
return packed
clean_teh content = let cleared = map rstrip `on` lines content
in unlines cleared
on = ($)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment