Jesper Axelsson avatar Jesper Axelsson committed 8ad3ea8

Refactored to use my own serious-waldcards liob for an extra boost

Comments (0)

Files changed (3)

 syntax: glob
 .dist-buildwrapper/*
+dist/*
+{-# LANGUAGE OverloadedStrings, BangPatterns  #-}
 module Main where
 
--- import Data.List as L
 import System.Environment as E
-import System.FilePath.Glob as G
 import System.Directory as D
-import Control.Monad 
+import System.FilePath
+
+import qualified Data.Text as T
+import qualified Data.Text.Wildcards as W
+
 
 
 
   where
     cons ~(h, t)        =  h : t
 
-matchPattern :: String -> [FilePath] -> IO [[FilePath]]
-matchPattern patt paths = liftM rmEmpty (mapM (G.globDir1 pattern) paths)
-        where pattern = G.compile patt
-              rmEmpty = filter (not . null)
               
+
+getPaths :: IO [String]
+getPaths = do
+    rawpaths <- E.getEnv "path"
+    return $ splitBy ';' rawpaths
+    
+
+getFiles :: String -> IO [FilePath]
+getFiles pat = do
+    paths <- getPaths
+    allOfIt <- mapM filtD
+                    (tail paths)
+    return $ concat allOfIt
+    where filtD p = filterDir (T.pack pat) p
+
+filterDir :: T.Text -> FilePath -> IO [FilePath]
+filterDir pat path = do 
+    itdoes <- D.doesDirectoryExist path
+    if itdoes
+     then do cont <- D.getDirectoryContents path
+             return $ map (path </>) $ filter ((W.match pat) . T.pack ) cont
+     else return []
+
 main::IO()
 main = do
     args <- getArgs
     if null args 
      then putStrLn "No file to search for given"
      else do
-        rawpaths <- E.getEnv "path"
-        let patt = head args
-            paths = splitBy ';' rawpaths
+        let !patt = head args
         putStrLn "-----------------------------"
-        yea <- liftM concat $ matchPattern patt paths
-        yea2 <- filterM D.doesFileExist yea
+        yea2 <- getFiles patt
         mapM_ putStrLn yea2
         putStrLn "-----------------------------"
         putStrLn "\nDone!"
                    base >= 4,
                    directory,
                    filepath,
-                   Glob
+                   serious-wildcards,
+                   text
 
   ghc-options:     -O2 -Wall
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.