Search Haskell source code from the command line
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin Adjust GH releases job Oct 8, 2017
main
src/Language/Haskell
.gitignore Merge branch 'master' into catch-exactprint-exceptions Oct 7, 2017
.travis.yml .travis.yml: test with stack-8.2.2.yaml Mar 27, 2018
CHANGELOG.md Update CHANGELOG and CONTRIBUTORS Oct 7, 2017
CONTRIBUTING.md Add CONTRIBUTING guidelines Oct 7, 2017
CONTRIBUTORS.md Update CHANGELOG and CONTRIBUTORS Oct 7, 2017
LICENSE Add a few Hackage requirements Oct 2, 2017
README.md
appveyor.yml Test with GHC 8.2.2 Dec 13, 2017
hgrep.cabal Relax lower bound on `directory` Oct 13, 2017
stack-8.0.1.yaml
stack-8.2.1.yaml Initial appveyor.yml Oct 12, 2017
stack-8.2.2.yaml stack-8.2.2.yaml: return to lts-10.10 Mar 27, 2018
stack.yaml stack.yaml: bump resolver to lts-9.21 Jan 8, 2018

README.md

hgrep

Travis Build Status AppVeyor Build Status Hackage page (downloads and API reference) Hackage-Deps

Search Haskell source code from the command line.

Powered by ghc-exactprint.

Usage

$> hgrep
Usage: hgrep [-e|--regex] EXPRESSION [FILE]

hgrep requires an expression and a set of files to search across.

An expression can be one of

  • The name of a type, e.g. FooBar
  • The name of an expression, e.g. foo
  • A regular expression (via the -e flag), e.g. -e Foo$

Each file will be parsed and searched. Results will be printed to the console, with syntax highlighting where possible.

Requirements

You can use cabal or stack to install, but you may need libpcre. In case you don't have it:

Ubuntu

sudo apt update
sudo apt install libpcre3-dev

Fedora

sudo dnf update
sudo dnf install pcre-devel

NixOS / Nix Package Manager

nix-env -i pcre

Install

Stack

git clone https://github.com/thumphries/hgrep.git
cd !$
stack install

Cabal

git clone https://github.com/thumphries/hgrep.git
cd !$
cabal new-build

Mafia

git clone https://github.com/thumphries/hgrep.git
cd !$
mafia build

Nix

git clone https://github.com/thumphries/hgrep.git
cd !$
nix-build -E 'with import <nixpkgs> {}; haskellPackages.callCabal2nix "hgrep" ./. {}'

Searching for top-level expressions

$> hgrep main main/hgrep.hs
main/hgrep.hs:16:1-13

-- | Run the program.
main :: IO ()
main/hgrep.hs:(17,1)-(18:27)

main = do
  putStrLn "Hello, world!"

Searching for type declarations

$> hgrep PrintOpts src/**/*.hs
src/Language/Haskell/HGrep/Internal/Data.hs:(40,1)-(42,28)

data PrintOpts = PrintOpts {
    poColourOpts :: ColourOpts
  } deriving (Eq, Ord, Show)

Searching with a regular expression

$> hgrep -e 'Opts$' src/**/*.hs
src/Language/Haskell/HGrep/Internal/Data.hs:(57,1)-(59,28)

data PrintOpts = PrintOpts {
    poColourOpts :: ColourOpts
  } deriving (Eq, Ord, Show)
src/Language/Haskell/HGrep/Internal/Data.hs:(61,1)-(64,26)

defaultPrintOpts :: PrintOpts
src/Language/Haskell/HGrep/Internal/Data.hs:(67,1)-(70,5)

defaultPrintOpts =
  PrintOpts {
      poColourOpts = DefaultColours
    }