Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created November 18, 2011 04:18
Show Gist options
  • Select an option

  • Save nbqx/1375595 to your computer and use it in GitHub Desktop.

Select an option

Save nbqx/1375595 to your computer and use it in GitHub Desktop.
haskell + mdfind sample
import Data.List
import System.Process
getList :: String -> IO [String]
getList kwd = do lst <- readProcess "mdfind" query ""
return $ lines lst
where
query = ["kMDItemContentType == \"public.folder\" && kMDItemDisplayName == \"*" ++ kwd ++ "*\"wcd"]
-- マッチ
includeMe :: String -> [String] -> [String]
includeMe kwd = filter (isInfixOf kwd)
-- アンマッチ
omitMe :: String -> [String] -> [String]
omitMe kwd = filter (not . isInfixOf kwd)
main :: IO ()
main = do l <- getList "test"
putStr . unlines $ fileFilter l
where
fileFilter = (omitMe "/Users/nbqx/Library") . (includeMe "/Users/nbqx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment