Convert Figma logo to code with AI

ggreer logothe_silver_searcher

A code-searching tool similar to ack, but faster.

26,054
1,422
26,054
552

Top Related Projects

47,483

ripgrep recursively searches directories for a regex pattern while respecting your gitignore

33,285

A simple, fast and user-friendly alternative to 'find'

63,665

:cherry_blossom: A command-line fuzzy finder

A code search tool similar to ack and the_silver_searcher(ag). It supports multi platforms and multi encodings.

1,601

A fast and powerful alternative to grep

Quick Overview

The Silver Searcher (ag) is a code searching tool similar to ack, but faster. It's designed to be a quicker alternative to grep, optimized for searching large codebases. The Silver Searcher is written in C and aims to be a cross-platform tool for developers.

Pros

  • Significantly faster than many other code search tools
  • Respects .gitignore and .ignore files for more relevant searches
  • Cross-platform compatibility (Linux, macOS, Windows)
  • Supports a wide range of file types and has customizable ignore patterns

Cons

  • May have a steeper learning curve for users accustomed to simpler grep commands
  • Some advanced regex features might not be supported
  • Can be overkill for small projects or simple searches
  • Requires installation, unlike built-in tools like grep

Getting Started

To install The Silver Searcher:

On macOS (using Homebrew):

brew install the_silver_searcher

On Ubuntu/Debian:

sudo apt-get install silversearcher-ag

On Windows (using Chocolatey):

choco install ag

Basic usage:

ag [OPTIONS] PATTERN [PATH]

Example searches:

ag "function" # Search for "function" in current directory
ag -i "case sensitive" # Case-insensitive search
ag --python "def main" # Search Python files for "def main"

For more options and advanced usage, refer to the project's documentation on GitHub.

Competitor Comparisons

47,483

ripgrep recursively searches directories for a regex pattern while respecting your gitignore

Pros of ripgrep

  • Faster performance, especially on large codebases
  • Better Unicode support
  • More configurable search options and output formats

Cons of ripgrep

  • Larger binary size
  • Slightly steeper learning curve due to more options
  • Less widespread adoption compared to The Silver Searcher

Code Comparison

The Silver Searcher:

ag "pattern" /path/to/search

ripgrep:

rg "pattern" /path/to/search

Both tools offer similar basic usage, but ripgrep provides more advanced options:

rg -i -t py "pattern" --glob "!tests/*"

This command searches for "pattern" case-insensitively (-i) in Python files (-t py), excluding the "tests" directory.

The Silver Searcher and ripgrep are both powerful code search tools, with ripgrep offering improved performance and features at the cost of a slightly larger footprint and complexity. The choice between them often comes down to personal preference and specific project requirements.

33,285

A simple, fast and user-friendly alternative to 'find'

Pros of fd

  • Written in Rust, offering better performance and memory safety
  • More user-friendly syntax and defaults (e.g., colorized output, smart case)
  • Supports parallel directory traversal for faster searches on multi-core systems

Cons of fd

  • Less mature project with potentially fewer features compared to The Silver Searcher
  • May not be as widely available in package managers or pre-installed on systems
  • Lacks some advanced regex features present in The Silver Searcher

Code Comparison

fd:

fd pattern
fd -e txt
fd -H pattern  # include hidden files

The Silver Searcher:

ag pattern
ag --file-search-regex '\.txt$'
ag --hidden pattern

Both tools offer similar functionality for searching files, but fd tends to have more intuitive syntax for common operations. The Silver Searcher provides more advanced regex capabilities out of the box, while fd focuses on simplicity and performance. Users familiar with find may find fd's syntax more natural, whereas those accustomed to grep might prefer The Silver Searcher's approach.

63,665

:cherry_blossom: A command-line fuzzy finder

Pros of fzf

  • More versatile: Can be used for fuzzy finding files, command history, and more
  • Interactive interface: Provides real-time feedback as you type
  • Highly customizable: Offers extensive configuration options

Cons of fzf

  • Not specialized for code search: May be slower for large codebases
  • Requires more setup: Needs integration with other tools for full functionality

Code comparison

fzf (interactive fuzzy finder):

find * -type f | fzf > selected

The Silver Searcher (fast code searching):

ag "pattern" /path/to/search

Key differences

  • Purpose: fzf is a general-purpose fuzzy finder, while The Silver Searcher is optimized for code searching
  • Usage: fzf is often used interactively, while The Silver Searcher is typically used in scripts or command-line operations
  • Performance: The Silver Searcher is generally faster for searching large codebases, while fzf excels in interactive use cases

Conclusion

Both tools serve different purposes and can complement each other in a developer's toolkit. fzf offers more flexibility and interactivity, while The Silver Searcher provides faster code searching capabilities.

A code search tool similar to ack and the_silver_searcher(ag). It supports multi platforms and multi encodings.

Pros of The Platinum Searcher

  • Written in Go, which can offer better cross-platform compatibility
  • Supports more file types out of the box
  • Includes built-in parallel directory traversal

Cons of The Platinum Searcher

  • Generally slower than The Silver Searcher for most operations
  • Less mature project with fewer contributors and updates
  • May consume more memory in some cases

Code Comparison

The Silver Searcher (C):

void *grep_thread(void *arg) {
  work_queue_t *queue_item;
  int worker_id = *(int *)arg;

  while (TRUE) {
    pthread_mutex_lock(&work_queue_mtx);

The Platinum Searcher (Go):

func (p *PlatinumSearcher) Search(root string, pattern *regexp.Regexp) {
    p.wg.Add(1)
    go p.find(root, pattern)
    p.wg.Wait()
}

func (p *PlatinumSearcher) find(root string, pattern *regexp.Regexp) {

Both projects aim to provide fast file searching capabilities, but they differ in implementation language and some features. The Silver Searcher is generally faster and more widely used, while The Platinum Searcher offers better cross-platform support and more built-in file type recognition. The code snippets show the different approaches to threading and concurrency in C versus Go.

1,601

A fast and powerful alternative to grep

Pros of sift

  • Written in Go, offering better cross-platform compatibility
  • Supports more advanced search patterns and regular expressions
  • Provides a more flexible configuration system

Cons of sift

  • Generally slower than The Silver Searcher for most operations
  • Less widespread adoption and community support
  • Fewer pre-built packages available for various operating systems

Code comparison

The Silver Searcher:

void *ag_malloc(size_t size) {
    void *ptr = malloc(size);
    if (ptr == NULL) {
        die("Memory allocation failed.");
    }
    return ptr;
}

sift:

func searchDir(dir string, opts *Options) ([]Match, error) {
    matches := []Match{}
    err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
        // Search logic here
    })
    return matches, err
}

Both projects aim to provide fast file searching capabilities, but they differ in implementation language and specific features. The Silver Searcher is written in C and focuses on speed, while sift is written in Go and offers more advanced search capabilities at the cost of some performance. The code snippets demonstrate the different programming paradigms used in each project.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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? Want to improve ag? I invite you to pair with me.

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/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

macOS

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 -a sys-apps/the_silver_searcher
    
  • Arch

      pacman -S the_silver_searcher
    
  • Slackware

      sbopkg -i the_silver_searcher
    
  • openSUSE

      zypper install the_silver_searcher
    
  • CentOS

      yum install the_silver_searcher
    
  • NixOS/Nix/Nixpkgs

      nix-env -iA silver-searcher
    
  • SUSE Linux Enterprise: Follow these simple instructions.

BSD

  • FreeBSD

      pkg install the_silver_searcher
    
  • OpenBSD/NetBSD

      pkg_add the_silver_searcher
    

Windows

  • Win32/64

    Unofficial daily builds are available.

  • winget

      winget install "The Silver Searcher"
    

    Notes:

    • This installs a release of ag.exe optimized for Windows.
    • winget is intended to become the default package manager client for Windows.
      As of June 2020, it's still in beta, and can be installed using instructions there.
    • The setup script in the Ag's winget package installs ag.exe in the first directory that matches one of these criteria:
      1. Over a previous instance of ag.exe from the same origin found in the PATH
      2. In the directory defined in environment variable bindir_%PROCESSOR_ARCHITECTURE%
      3. In the directory defined in environment variable bindir
      4. In the directory defined in environment variable windir
  • Chocolatey

      choco install ag
    
  • MSYS2

      pacman -S mingw-w64-{i686,x86_64}-ag
    
  • 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):

    • macOS:

        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 zlib-devel
      
    • openSUSE:

        zypper source-install --build-deps-only the_silver_searcher
      
    • 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
    
  3. 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.

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.
  • ack.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.
  • fzf - A command-line fuzzy finder
  • ripgrep
  • Sack - A utility that wraps Ack and Ag. It removes a lot of repetition from searching and opening matching files.