Giter VIP home page Giter VIP logo

the_silver_searcher's Introduction

The Silver Searcher

A code searching tool similar to ack, with a focus on speed.

Build Status

Floobits Status

#ag on Freenode

Do you know C? I invite you to pair with me to help me get to Ag 1.0.

What's so great about Ag?

  • It is an order of magnitude faster than ack.
  • It ignores file patterns from your .gitignore and .hgignore.
  • If there are files in your source repo you don't want to search, just add their patterns to a .ignore file. (*cough* *.min.js *cough*)
  • The command name is 33% shorter than ack, and all keys are on the home row!

Ag is quite stable now. Most changes are new features, minor bug fixes, or performance improvements. It's much faster than Ack in my benchmarks:

ack test_blah ~/code/  104.66s user 4.82s system 99% cpu 1:50.03 total

ag test_blah ~/code/  4.67s user 4.58s system 286% cpu 3.227 total

Ack and Ag found the same results, but Ag was 34x faster (3.2 seconds vs 110 seconds). My ~/code directory is about 8GB. Thanks to git/hg/svn-ignore, Ag only searched 700MB of that.

There are also graphs of performance across releases.

How is it so fast?

  • Ag uses Pthreads to take advantage of multiple CPU cores and search files in parallel.
  • Files are mmap()ed instead of read into a buffer.
  • Literal string searching uses Boyer-Moore strstr.
  • Regex searching uses PCRE's JIT compiler (if Ag is built with PCRE >=8.21).
  • Ag calls pcre_study() before executing the same regex on every file.
  • Instead of calling fnmatch() on every pattern in your ignore files, non-regex patterns are loaded into arrays and binary searched.

I've written several blog posts showing how I've improved performance. These include how I added pthreads, wrote my own scandir(), benchmarked every revision to find performance regressions, and profiled with gprof and Valgrind.

Installing

OS X

brew install the_silver_searcher

or

port install the_silver_searcher

Linux

  • Ubuntu >= 13.10 (Saucy) or Debian >= 8 (Jessie)

      apt-get install silversearcher-ag
    
  • Fedora 21 and lower

      yum install the_silver_searcher
    
  • Fedora 22+

      dnf install the_silver_searcher
    
  • RHEL7+

      yum install epel-release.noarch the_silver_searcher
    
  • Gentoo

      emerge the_silver_searcher
    
  • Arch

      pacman -S the_silver_searcher
    
  • Slackware

      sbopkg -i the_silver_searcher
    

BSD

  • FreeBSD

      pkg install the_silver_searcher
    
  • OpenBSD/NetBSD

      pkg_add the_silver_searcher
    

Cygwin

Run the relevant setup-*.exe, and select "the_silver_searcher" in the "Utils" category.

Building from source

Building master

  1. Install dependencies (Automake, pkg-config, PCRE, LZMA):

    • OS X:

        brew install automake pkg-config pcre xz
      

      or

        port install automake pkgconfig pcre xz
      
    • Ubuntu/Debian:

        apt-get install -y automake pkg-config libpcre3-dev zlib1g-dev liblzma-dev
      
    • Fedora:

        yum -y install pkgconfig automake gcc zlib-devel pcre-devel xz-devel
      
    • CentOS:

        yum -y groupinstall "Development Tools"
        yum -y install pcre-devel xz-devel
      
    • Windows: It's complicated. See this wiki page.

  2. Run the build script (which just runs aclocal, automake, etc):

     ./build.sh
    

On Windows (inside an msys/MinGW shell):

    make -f Makefile.w32
  1. Make install:

     sudo make install
    

Building a release tarball

GPG-signed releases are available here.

Building release tarballs requires the same dependencies, except for automake and pkg-config. Once you've installed the dependencies, just run:

./configure
make
make install

You may need to use sudo or run as root for the make install.

Editor Integration

Vim

You can use Ag with [ack.vim][] by adding the following line to your .vimrc:

let g:ackprg = 'ag --nogroup --nocolor --column'

or:

let g:ackprg = 'ag --vimgrep'

Which has the same effect but will report every match on the line.

There's also a fork of ack.vim tailored for use with Ag: [ag.vim][] [ack.vim]: https://github.com/mileszs/ack.vim [ag.vim]: https://github.com/rking/ag.vim

Emacs

You can use ag.el as an Emacs front-end to Ag. See also: helm-ag.

TextMate

TextMate users can use Ag with my fork of the popular AckMate plugin, which lets you use both Ack and Ag for searching. If you already have AckMate you just want to replace Ack with Ag, move or delete "~/Library/Application Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack" and run ln -s /usr/local/bin/ag "~/Library/Application Support/TextMate/PlugIns/AckMate.tmplugin/Contents/Resources/ackmate_ack"

Other stuff you might like

  • Ack - Better than grep. Without Ack, Ag would not exist.
  • AckMate - An ack-powered replacement for TextMate's slow built-in search.
  • ack.vim
  • ag.vim
  • Exuberant Ctags - Faster than Ag, but it builds an index beforehand. Good for really big codebases.
  • Git-grep - As fast as Ag but only works on git repos.
  • Sack - A utility that wraps Ack and Ag. It removes a lot of repetition from searching and opening matching files.

the_silver_searcher's People

Contributors

adolfopa avatar avih avatar ban-dana avatar blueyed avatar c4rlo avatar dnelson avatar elliot-forty-two avatar epmatsw avatar gentoo90 avatar ggreer avatar greg0ire avatar gurgeous avatar jdhore avatar k-takata avatar luksen avatar masklinn avatar mattn avatar me-and avatar monochromegane avatar n0la avatar nall avatar pquerna avatar rioderelfte avatar rrebello avatar sebgod avatar sjl avatar snoringfrog avatar timbertson avatar tonyo avatar umanwizard avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.