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

The Platinum Searcher Build Status wercker status

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

Features

  • It searches code about 3–5× faster than ack.
  • It searches code as fast as the_silver_searcher(ag).
  • It ignores file patterns from your .gitignore.
  • It ignores directories with names that start with ., eg .config. Use --hidden option, if you want to search.
  • It searches UTF-8, EUC-JP and Shift_JIS files.
  • It provides binaries for multi platform (macOS, Windows, Linux).

Benchmarks

cd ~/src/github.com/torvalds/linux
ack EXPORT_SYMBOL_GPL 30.18s user 2.32s system  99% cpu 32.613 total # ack
ag  EXPORT_SYMBOL_GPL  1.57s user 1.76s system 311% cpu  1.069 total # ag: It's faster than ack.
pt  EXPORT_SYMBOL_GPL  2.29s user 1.26s system 358% cpu  0.991 total # pt: It's faster than ag!!

Usage

$ # Recursively searches for PATTERN in current directory.
$ pt PATTERN

$ # You can specify PATH and some OPTIONS.
$ pt OPTIONS PATTERN PATH

Configuration

If you put configuration file on the following directories, pt use option in the file.

  • $XDG_CONFIG_HOME/pt/config.toml
  • $HOME/.ptconfig.toml
  • .ptconfig.toml (current directory)

The file is TOML format like the following.

color = true
context = 3
ignore = ["dir1", "dir2"]
color-path = "1;34"

The options are same as command line options.

Editor Integration

Vim + Unite.vim

You can use pt with Unite.vim.

nnoremap <silent> ,g :<C-u>Unite grep:. -buffer-name=search-buffer<CR>
if executable('pt')
  let g:unite_source_grep_command = 'pt'
  let g:unite_source_grep_default_opts = '--nogroup --nocolor'
  let g:unite_source_grep_recursive_opt = ''
  let g:unite_source_grep_encoding = 'utf-8'
endif

Emacs + pt.el

You can use pt with pt.el, which can be installed from MELPA.

Installation

Developer

$ go get -u github.com/monochromegane/the_platinum_searcher/...

User

Download from the following url.

Or, you can use Homebrew (Only macOS).

$ brew install pt

pt is an alias for the_platinum_searcher in Homebrew.

Contribution

  1. Fork it
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the go test ./... command and confirm that it passes
  6. Run gofmt -s
  7. Create new Pull Request

License

MIT

Author

monochromegane

Comments
  • pt crashes on doing simple search

    pt crashes on doing simple search

    Hi there,

    Have started using pt recently. Pt is crashing constantly when trying to search over a directory.

    I am getting this error. runtime/cgo: pthread_create failed: Resource temporarily unavailable SIGABRT: abort PC=0xf77afa30 m=2 ...

    The full log is with me however I am getting "Attaching documents requires write permission to this repository. Choose Files Try again with a PNG, GIF, or JPG." when I try to attach the log with this issue.

  • オプションのパスの末尾に\をつけるとruntime panicでおちる

    オプションのパスの末尾に\をつけるとruntime panicでおちる

    @d_ymkw says the following on Twitter.

    @monochromegane はじめまして。Windows環境(x64)下で、
    pt利用させて頂いています。ところで、実用上問題はないのですが、
    オプションのパスの末尾に\をつけると、runtime panicで落ちます。
    ご確認頂ければと思います。
    
  • How to do escape in regex PATTERN?

    How to do escape in regex PATTERN?

    I would like to search for sort function call case insensitively in my code. This does not work:

    $ pt -i sort\(
    error parsing regexp: missing closing ): `(?i)(sort()`
    

    pt sort\( works correctly for small letter case, but I would like to search case insensitively. -i causes pt to use regex.

    $ pt --version
    1.7.4
    

    Related to #62.

  • Add --column argument

    Add --column argument

    Implements #37.

    $  pt --column Test
    grep_test.go:
    24:6:func TestGrep(t *testing.T) {
    45:6:func TestGrepWithStream(t *testing.T) {
    
    pattern_test.go:
    12:6:func TestIgnoreCaseWithSmartCase(t *testing.T) {
    
    ignore_test.go:
    16:6:func TestGenericIgnoreMatch(t *testing.T) {
    34:6:func TestGitIgnoreMatch(t *testing.T) {
    67:6:func TestGitIgnoreMatchOnSubDirectory(t *testing.T) {
    ...
    
    $ pt --nocolor --nogroup --column Test
    grep_test.go:24:6:func TestGrep(t *testing.T) {
    grep_test.go:45:6:func TestGrepWithStream(t *testing.T) {
    file_test.go:23:6:func TestIdentifyType(t *testing.T) {
    match_test.go:49:6:func TestMatch(t *testing.T) {
    match_test.go:76:6:func TestMatchWhenContextAndMatchDuplicate(t *testing.T) {
    find_test.go:28:6:func TestFind(t *testing.T) {
    ...
    

    Then I could add this for Ack.vim plugin

    let g:ackprg = 'pt --nogroup --nocolor --column'
    
  • Enhancement Request: Support for -A, -B and -C options

    Enhancement Request: Support for -A, -B and -C options

    Hi, could you please provide the -A, -B and -C options similar to what grep has?

    Also, does this follow symlinks by default? Is there a way to make it follow (or not follow) symlinks explicitly?

    Thanks for the great tool :+1:

  • ctrl-c during printout causes panic

    ctrl-c during printout causes panic

    I really like this idea (ag/ack in go)! Great job!

    Here's a low-priority issue I found: pressing ctrl-c while the results are printing causes a panic. go 1.2, Mac 10.8.

    Partial stacktrace:

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xb code=0x1 addr=0x40 pc=0x40966a4]
    
    goroutine 8 [running]:
    runtime.panic(0x40dffc0, 0x423ae59)
        /usr/local/go/src/pkg/runtime/panic.c:266 +0xb6
    github.com/monochromegane/the_platinum_searcher/search/file.IdentifyType(0xc2100ef800, 0x30, 0x0, 0x0)
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/search/file/file.go:28 +0xb4
    github.com/monochromegane/the_platinum_searcher/search/find.func·001(0xc2100ef800, 0x30, 0x4411178, 0xc2149be1e0, 0x4, ...)
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/search/find/find.go:51 +0x7f1
    github.com/monochromegane/the_platinum_searcher/search/find.walk(0xc2100ef800, 0x30, 0x4411178, 0xc2149be1e0, 0x4, ...)
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/search/find/find.go:78 +0x9c
    github.com/monochromegane/the_platinum_searcher/search/find.walk(0xc210066be0, 0x1c, 0x4411178, 0xc2100931e0, 0x4, ...)
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/search/find/find.go:103 +0x66b
    github.com/monochromegane/the_platinum_searcher/search/find.walk(0xc210066240, 0x12, 0x4411178, 0xc2100680a0, 0x3, ...)
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/search/find/find.go:103 +0x66b
    github.com/monochromegane/the_platinum_searcher/search/find.walkOnGoRoutine(0xc210066240, 0x12, 0x4411178, 0xc2100680a0, 0xc21006f000, ...)
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/search/find/find.go:73 +0x87
    created by github.com/monochromegane/the_platinum_searcher/search/find.walk
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/search/find/find.go:100 +0x489
    
    goroutine 1 [chan receive]:
    github.com/monochromegane/the_platinum_searcher/search.(*Searcher).Search(0xc21001e5d0)
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/search/search.go:22 +0x119
    main.main()
        /Users/justin/dev/go/src/github.com/monochromegane/the_platinum_searcher/main.go:54 +0x347
    
    goroutine 3 [syscall]:
    runtime.goexit()
        /usr/local/go/src/pkg/runtime/proc.c:1394
    
  • the `pt` command built by `go get -u` does nothing

    the `pt` command built by `go get -u` does nothing

    I might be wrong, but go get -u github.com/monochromegane/the_platinum_searcher/... resulted in a pt command without doing anything. I had to do go build -o pt cmd/pt/main.go instead to build a workable pt command in the source directory. I'm not familiar with the golang yet, but I guess you need to add something for building a workable pt command with the go get -u command sequence. The execution environment is based on FreeBSD 11.0-STABLE and Ports (go-1.8_1,1).

  • --ignore-case with -g option

    --ignore-case with -g option

    Option -g doesn't respect neither -i nor -S options, so there is no way match path pattern case insensitively.

    For example Given pwd files

    ├── context
    │   └── context.txt
    ├── depth
    │   ├── Context.txt
    │   ├── dir_1
    │   │   ├── dir_2
    │   │   │   └── file_3.txt
    │   │   └── file_2.txt
    │   └── file_1.txt
    

    running pt -ig context produces context/context.txt.

    should:

    depth/Context.txt
    context/context.txt
    
  • [EXPIRED] Show only matching part

    [EXPIRED] Show only matching part

    Input

    host -t A wikipedia.org | openssl dgst -sha256 | pt /N /e [A-Fa-f0-9]{64}
    

    Output

    (stdin)= 0d00409623da8ae039de83200af7f6fa9211bb13e1b3e10ea45142cd08b3e50b
    

    Hash is coloured, but I need that coloured part only. How?

  • how to use --ignore?

    how to use --ignore?

    i am using this pt --ignore-case --ignore=["*.html","*.js"] lib/but its not ignoring those files with those extensions. am i doing something wrong?

  • Colour not being shown in Windows command prompt

    Colour not being shown in Windows command prompt

    Instead of seeing colours, I'm seeing the escape sequence ←[1;33m10768←[0m←. I also get the same in another command prompt I use (ConEmu).

    If it helps, ack shows colours correctly but ag doesn't!

  • Cannot install on ubuntu 22.04

    Cannot install on ubuntu 22.04

    Hi. I tried to install with go on ubuntu 22.04, but seems to fail.

    $ go install github.com/monochromegane/the_platinum_searcher@latest
    go: finding module for package github.com/monochromegane/conflag
    go: finding module for package golang.org/x/text/transform
    go: finding module for package github.com/shiena/ansicolor
    go: finding module for package github.com/jessevdk/go-flags
    go: finding module for package golang.org/x/text/encoding/japanese
    go: finding module for package github.com/monochromegane/terminal
    go: finding module for package github.com/monochromegane/go-home
    go: finding module for package github.com/monochromegane/go-gitignore
    go: found github.com/jessevdk/go-flags in github.com/jessevdk/go-flags v1.5.0
    go: found github.com/monochromegane/conflag in github.com/monochromegane/conflag v0.0.0-20151130130520-6d68c9aa4183
    go: found github.com/monochromegane/go-gitignore in github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00
    go: found github.com/monochromegane/go-home in github.com/monochromegane/go-home v0.0.0-20151024104835-25d9dda59392
    go: found github.com/monochromegane/terminal in github.com/monochromegane/terminal v0.0.0-20161222050454-9bc47e2707d9
    go: found github.com/shiena/ansicolor in github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18
    go: found golang.org/x/text/encoding/japanese in golang.org/x/text v0.4.0
    go: found golang.org/x/text/transform in golang.org/x/text v0.4.0
    go: finding module for package gopkg.in/yaml.v2
    go: finding module for package github.com/BurntSushi/toml
    go: found github.com/BurntSushi/toml in github.com/BurntSushi/toml v1.2.1
    go: found gopkg.in/yaml.v2 in gopkg.in/yaml.v2 v2.4.0
    package github.com/monochromegane/the_platinum_searcher is not a main package
    

    My environment is:

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 22.04.1 LTS
    Release:	22.04
    Codename:	jammy
    $ go version
    go version go1.19.3 linux/amd64
    
  • a path with trailing slash results doubled slash path

    a path with trailing slash results doubled slash path

    When the path with a trailing slash like path/to/dir/ is set to the PATH argument, the file paths in the result become doubled slash paths like path/to/dir//found/file.txt.

    It would be good to clean the paths.

    example::

    $ tree
    .
    └── examples
        ├── a
        │   └── A.txt
        ├── b
        │   └── B.txt
        └── c
    
    4 directories, 2 files
    $ pt hello examples/
    examples//a/A.txt
    1:hello
    
    examples//b/B.txt
    1:hello world
    
  • Case sensitive option

    Case sensitive option

    case insensitive has an option:

    -i, --ignore-case
    

    but once you turn it on, you cannot turn it off. That option could look like this:

    -s, --case-sensitive
    

    If this option existed, you could write a function like this:

    pt_bravo() {
       pt -i "$@"
    }
    

    then if you passed the new argument like this:

    pt_bravo -s charlie delta.txt
    

    the command line argument would override the function argument, as it comes after.

An open source, online coding platform that offers code practice and tutoring in 50 different programming languages
An open source, online coding platform that offers code practice and tutoring in 50 different programming languages

Exercism Golang En este repositorio voy a subir los ejercicios de la plataforma

Jan 7, 2022
Markdown version of Reverse Engineering the source code of the BioNTech/Pfizer SARS-CoV-2 Vaccine

The big BNT162b2 archive All vaccine data here is sourced from this World Health Organization document. This describes the RNA contents of the BNT162b

Dec 2, 2022
Go-Notebook is inspired by Jupyter Project (link) in order to document Golang code.
Go-Notebook is inspired by Jupyter Project (link) in order to document Golang code.

Go-Notebook Go-Notebook is an app that was developed using go-echo-live-view framework, developed also by us. GitHub repository is here. For this proj

Jan 9, 2023
Example code for my Cadence Intro Workshop

Temporal Intro Workshop This repository contains example code for my Temporal Intro Workshop. Prerequisites Git, Make, etc. Make sure you have the lat

Dec 18, 2022
Sample code for my Go Deadlocks talk

Go Deadlocks Talk This is sample code for my Go Deadlocks talk. Simple simple - a super simple deadlock simple2 - the same but with an extra Go deadlo

Jul 30, 2022
Test-Driven Development code kata in Golang

Bowling Kata Golang Test-Driven Development code kata in Golang Bowling Rules The game consists of 10 frames. In each frame the player has two rolls t

Jan 5, 2022
A series of small code snipppets & exercises to learn Go.

Learning-Go A series of small code snipppets & exercises to learn Go. WARNING: During this excercise you will be learning along with me, I am not your

Dec 18, 2021
Source code of the 100 Go Mistakes book

100 Go Mistakes and How to Avoid Them Source code of 100 Go Mistakes and How to Avoid Them. Table of Contents Chapter 1 - Introduction Chapter 2 - Cod

Dec 30, 2022
VHDL Simulator, code VHDL in your browser! 🤖
VHDL Simulator, code VHDL in your browser! 🤖

VHDL Runner ?? VHDL Simulator, code VHDL in your browser! ?? Usage Go to https://vhdl.mateuszwozniak.com/ Next, type some VHDL code, with appropriate

Feb 6, 2022
Code solution for question against internship application at Eluvio

Eluvio Problem Statement Imagine you have a program that needs to look up information about items using their item ID, often in large batches. Unfortu

Feb 5, 2022
Mastering-go-exercises - Some code examples from Mihalis Tsoukalos book titled Mastering GO

Mastering go exercises This is a training repository. Here are some code example

Feb 16, 2022
Tool (in Go!) to compare and diff container and host environments. Dinosaur fun!

Compe compare environments and other things between containers, and host ??️ This is a simple tool to compare environments and other features of conta

Sep 24, 2022
Tool to modify Snapmaker laser GCode for a rotary module to include z movements

lasery2z Tool to modify Snapmaker laser GCode for a rotary module to include z movements. Background Snapmaker's Luban tool to generate 4D laser proje

Sep 13, 2021
ebk is a tiny tool for ebook

ebk ebk is a tiny tool for ebook. Usage ebk ls list directory ebook contents. $

Mar 25, 2022
Go Cheat Sheet - An overview of Go syntax and features.

Go Cheat Sheet - An overview of Go syntax and features.

Dec 31, 2022
An online book focusing on Go syntax/semantics and runtime related things

Go 101 is a book focusing on Go syntax/semantics and all kinds of runtime related things. It tries to help gophers gain a deep and thorough understanding of Go. This book also collects many details of Go and in Go programming. The book is expected to be helpful for both beginner and experienced Go programmers.

Dec 29, 2022
This slide deck and supporting material is part of the Introduction to Go training course by Dave Cheney

This slide deck and supporting material is part of the Introduction to Go training course by Dave Cheney.

Nov 14, 2022
📖 Build a RESTful API on Go: Fiber, PostgreSQL, JWT and Swagger docs in isolated Docker containers.
📖 Build a RESTful API on Go: Fiber, PostgreSQL, JWT and Swagger docs in isolated Docker containers.

?? Tutorial: Build a RESTful API on Go Fiber, PostgreSQL, JWT and Swagger docs in isolated Docker containers. ?? The full article is published on Marc

Dec 27, 2022
1000+ Hand-Crafted Go Examples, Exercises, and Quizzes

A Huge Number of Go Examples, Exercises and Quizzes Best way of learning is doing. Inside this repository, you will find thousands of Go examples, exe

Jan 1, 2023