Search for terms from a tags file

This returns a list of each match, files, and counts based on the
current directory.
This commit is contained in:
Joshua Clayton 2016-04-28 17:42:58 -04:00
parent 8931c08f93
commit 1249a0e823
4 changed files with 31 additions and 9 deletions

View File

@ -1,6 +1,9 @@
module Main where
import Lib
import Unused.TermSearch (search)
main :: IO ()
main = someFunc
main = do
tokens <- pure . lines =<< getContents
results <- pure . concat =<< mapM search tokens
putStrLn $ unlines results

View File

@ -1,6 +0,0 @@
module Lib
( someFunc
) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"

24
src/Unused/TermSearch.hs Normal file
View File

@ -0,0 +1,24 @@
module Unused.TermSearch
( search
) where
import System.IO
import System.Process
search :: String -> IO [String]
search t = do
results <- ag t
return $ linesMap prefixTerm results
where
prefixTerm = ((++) t)
linesMap :: (String -> String) -> String -> [String]
linesMap f =
filter empty . map f . lines
where
empty = ((/=) 0) . length
ag :: String -> IO String
ag t = do
(_, results, _) <- readProcessWithExitCode "ag" [t, ".", "-c", "-Q", "--ackmate"] ""
return results

View File

@ -15,8 +15,9 @@ cabal-version: >=1.10
library
hs-source-dirs: src
exposed-modules: Lib
exposed-modules: Unused.TermSearch
build-depends: base >= 4.7 && < 5
, process
default-language: Haskell2010
executable unused