the_platinum_searcher

package module
v2.1.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2016 License: MIT Imports: 22 Imported by: 0

README

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 searches UTF-8, EUC-JP and Shift_JIS files.
  • It provides binaries for multi platform (Mac OS X, 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 searchs for PATTERN in current directory.
$ pt PATTERN

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

Configuration

.ptconfig.toml

If you put .ptconfig.toml on $HOME or current directory, pt use option in the file. 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 MacOSX).

$ 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

Documentation

Index

Constants

View Source
const (
	ColorReset = "\x1b[0m\x1b[K"

	SeparatorColon  = ":"
	SeparatorHyphen = "-"
)
View Source
const (
	UNKNOWN = iota
	ERROR
	BINARY
	ASCII
	UTF8
	EUCJP
	SHIFTJIS
)
View Source
const (
	ExitCodeOK = iota
	ExitCodeError
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option struct {
	Version      bool          `long:"version" description:"Show version"`
	OutputOption *OutputOption `group:"Output Options"`
	SearchOption *SearchOption `group:"Search Options"`
}

Top level options

type OutputOption

type OutputOption struct {
	Color               func()       `long:"color" description:"Print color codes in results (default: true)"`
	NoColor             func()       `long:"nocolor" description:"Don't print color codes in results (default: false)"`
	ForceColor          bool         // Force color. Not user option.
	EnableColor         bool         // Enable color. Not user option.
	ColorLineNumber     func(string) `long:"color-line-number" description:"Color codes for line numbers (default: 1;33)"`
	ColorPath           func(string) `long:"color-path" description:"Color codes for path names (default: 1;32)"`
	ColorMatch          func(string) `long:"color-match" description:"Color codes for result matches (default: 30;43)"`
	ColorCodeLineNumber string       // Color line numbers. Not user option.
	ColorCodePath       string       // Color path names. Not user option.
	ColorCodeMatch      string       // Color result matches. Not user option.
	Group               func()       `long:"group" description:"Print file name at header (default: true)"`
	NoGroup             func()       `long:"nogroup" description:"Don't print file name at header (default: false)"`
	ForceGroup          bool         // Force group. Not user option.
	EnableGroup         bool         // Enable group. Not user option.
	Column              bool         `long:"column" description:"Print column (default: false)"`
	After               int          `short:"A" long:"after" description:"Print lines after match"`
	Before              int          `short:"B" long:"before" description:"Print lines before match"`
	Context             int          `short:"C" long:"context" description:"Print lines before and after match"`
	FilesWithMatches    bool         `short:"l" long:"files-with-matches" description:"Only print filenames that contain matches"`
	Count               bool         `short:"c" long:"count" description:"Only print the number of matching lines for each input file."`
	OutputEncode        string       `short:"o" long:"output-encode" description:"Specify output encoding (none, jis, sjis, euc)"`
}

Output options.

func (*OutputOption) SetColorLineNumber

func (o *OutputOption) SetColorLineNumber(code string)

func (*OutputOption) SetColorMatch

func (o *OutputOption) SetColorMatch(code string)

func (*OutputOption) SetColorPath

func (o *OutputOption) SetColorPath(code string)

func (*OutputOption) SetDisableColor

func (o *OutputOption) SetDisableColor()

func (*OutputOption) SetDisableGroup

func (o *OutputOption) SetDisableGroup()

func (*OutputOption) SetEnableColor

func (o *OutputOption) SetEnableColor()

func (*OutputOption) SetEnableGroup

func (o *OutputOption) SetEnableGroup()

type PlatinumSearcher

type PlatinumSearcher struct {
	Out, Err io.Writer
}

func (PlatinumSearcher) Run

func (p PlatinumSearcher) Run(args []string) int

type SearchOption

type SearchOption struct {
	Regexp                 bool         `` /* 168-byte string literal not displayed */
	IgnoreCase             bool         `short:"i" long:"ignore-case" description:"Match case insensitively"`
	SmartCase              bool         `short:"S" long:"smart-case" description:"Match case insensitively unless PATTERN contains uppercase characters"`
	WordRegexp             bool         `short:"w" long:"word-regexp" description:"Only match whole words"`
	Ignore                 []string     `long:"ignore" description:"Ignore files/directories matching pattern"`
	VcsIgnore              []string     `long:"vcs-ignore" description:"VCS ignore files" default:".gitignore"`
	GlobalGitIgnore        bool         `long:"global-gitignore" description:"Use git's global gitignore file for ignore patterns"`
	HomePtIgnore           bool         `long:"home-ptignore" description:"Use $Home/.ptignore file for ignore patterns"`
	SkipVcsIgnore          bool         `short:"U" long:"skip-vcs-ignores" description:"Don't use VCS ignore file for ignore patterns"`
	FilesWithRegexp        func(string) `short:"g" description:"Print filenames matching PATTERN"`
	EnableFilesWithRegexp  bool         // Enable files with regexp. Not user option.
	PatternFilesWithRegexp string       // Pattern files with regexp. Not user option.
	FileSearchRegexp       string       `short:"G" long:"file-search-regexp" description:"PATTERN Limit search to filenames matching PATTERN"`
	Depth                  int          `long:"depth" default:"25" description:"Search up to NUM directories deep"`
	Follow                 bool         `short:"f" long:"follow" description:"Follow symlinks"`
	Hidden                 bool         `long:"hidden" description:"Search hidden files and directories"`
	SearchStream           bool         // Input from pipe. Not user option.
}

Search options.

func (*SearchOption) SetFilesWithRegexp

func (o *SearchOption) SetFilesWithRegexp(p string)

Directories

Path Synopsis
cmd
pt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL