the_platinum_searcher

package module
v1.7.7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2015 License: MIT Imports: 14 Imported by: 0

README

The Platinum Searcher

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 and .hgignore.
  • It searches UTF-8, EUC-JP and Shift_JIS files.
  • It provides binaries for multi platform (Mac OS X, Windows, Linux).
Benchmarks
ack go  6.24s user 1.06s system 99%  cpu 7.304 total # ack:
ag go   0.88s user 1.39s system 221% cpu 1.027 total # ag:  It's faster than ack
pt go   1.09s user 1.01s system 235% cpu 0.892 total # pt:  It's faster than ag!!

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.

Usage

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

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

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.

Code Status

wercker status

Build Status

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Index

Constants

View Source
const (
	ColorReset      = "\x1b[0m\x1b[K"
	ColorLineNumber = "\x1b[1;33m"  /* yellow with black background */
	ColorPath       = "\x1b[1;32m"  /* bold green */
	ColorMatch      = "\x1b[30;43m" /* black with yellow background */
)
View Source
const (
	UNKNOWN = iota
	ERROR
	BINARY
	ASCII
	UTF8
	EUCJP
	SHIFTJIS
)

Variables

View Source
var FileMatchCount, MatchCount uint
View Source
var FilesSearched uint

Functions

func Find

func Find(roots []string, pattern *Pattern, out chan *GrepParams, option *Option)

func Grep

func Grep(in chan *GrepParams, out chan *PrintParams, option *Option)

func IdentifyType

func IdentifyType(path string) int

func Print

func Print(in chan *PrintParams, done chan struct{}, option *Option)

func Walk

func Walk(root string, ignores ignoreMatchers, follow bool, walkFn WalkFunc) error

Types

type Color added in v1.7.3

type Color struct {
}

type Decorator added in v1.7.3

type Decorator interface {
	// contains filtered or unexported methods
}

type FileInfo

type FileInfo struct {
	os.FileInfo
	// contains filtered or unexported fields
}

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool
func (f *FileInfo) IsSymlink() bool

type GrepParams

type GrepParams struct {
	Path    string
	Encode  int
	Pattern *Pattern
}

type Line

type Line struct {
	Num int
	Str string
}

type Match

type Match struct {
	Matched bool
	*Line

	Befores []*Line
	Afters  []*Line
	Col     int
	// contains filtered or unexported fields
}

func NewMatch

func NewMatch(before, after int, setCol bool) *Match

func (*Match) FirstLineNum

func (m *Match) FirstLineNum() int

func (*Match) IsMatch

func (m *Match) IsMatch(pattern *Pattern, num int, s string) (*Match, bool)

func (*Match) LastLineNum

func (m *Match) LastLineNum() int

func (*Match) LineNum

func (m *Match) LineNum() int

func (*Match) Match

func (m *Match) Match() string

type Option

type Option struct {
	Color             func()   `long:"color" description:"Print color codes in results (Enabled by default)"`
	NoColor           func()   `long:"nocolor" description:"Don't print color codes in results (Disabled by default)"`
	ForceColor        bool     // Force color.  Not user option.
	EnableColor       bool     // Enable color. Not user option.
	NoGroup           bool     `long:"nogroup" description:"Don't print file name at header (Disabled by default)"`
	Column            bool     `long:"column" description:"Print column (Disabled by default)"`
	FilesWithMatches  bool     `short:"l" long:"files-with-matches" description:"Only print filenames that contain matches"`
	VcsIgnore         []string `long:"vcs-ignore" description:"VCS ignore files" default:".gitignore" default:".hgignore" default:".ptignore"`
	NoPtIgnore        bool     `long:"noptignore" description:"Don't use default ($Home/.ptignore) file for ignore patterns"`
	NoGlobalGitIgnore bool     `long:"noglobal-gitignore" description:"Don't use git's global gitignore file for ignore patterns"`
	SkipVcsIgnore     func()   `short:"U" long:"skip-vsc-ignores" description:"Don't use VCS ignore file for ignore patterns. Still obey .ptignore"`

	Hidden           bool     `short:"H" long:"hidden" description:"Search hidden files and directories"`
	Ignore           []string `long:"ignore" description:"Ignore files/directories matching pattern"`
	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"`
	FilesWithRegexp  string   `short:"g" description:"Print filenames matching PATTERN"`
	FileSearchRegexp string   `short:"G" long:"file-search-regexp" description:"PATTERN Limit search to filenames matching PATTERN"`
	Depth            int      `long:"depth" default:"25" default-mask:"-" description:"Search up to NUM directories deep (Default: 25)"`
	Follow           bool     `short:"f" long:"follow" description:"Follow symlinks"`
	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"`
	OutputEncode     string   `short:"o" long:"output-encode" description:"Specify output encoding (none, jis, sjis, euc)"`
	SearchStream     bool     // Input from pipe. Not user option.
	Regexp           bool     `short:"e" description:"Parse PATTERN as a regular expression (Disabled by default)"`
	WordRegexp       bool     `short:"w" long:"word-regexp" description:"Only match whole words"`
	Proc             int      // Number of goroutine. Not user option.
	Stats            bool     `long:"stats" description:"Print stats about files scanned, time taken, etc"`
	Version          bool     `long:"version" description:"Show version"`
	// contains filtered or unexported fields
}

func (*Option) SetDisableColor

func (o *Option) SetDisableColor()

func (*Option) SetEnableColor

func (o *Option) SetEnableColor()

func (*Option) SkipVcsIgnores added in v1.7.3

func (o *Option) SkipVcsIgnores()

func (*Option) VcsIgnores

func (o *Option) VcsIgnores() []string

type Pattern

type Pattern struct {
	Pattern    string
	Regexp     *regexp.Regexp
	FileRegexp *regexp.Regexp
	IgnoreCase bool
	UseRegexp  bool
}

func NewPattern

func NewPattern(pattern, filePattern string, smartCase, ignoreCase, useRegexp bool) (*Pattern, error)

type Plain added in v1.7.3

type Plain struct {
}

type PlatinumSearcher

type PlatinumSearcher struct {
	Roots   []string
	Pattern string
	Option  *Option
}

func (*PlatinumSearcher) Search

func (p *PlatinumSearcher) Search() error

type PrintParams

type PrintParams struct {
	Pattern *Pattern
	Path    string
	Matches []*Match
}

type WalkFunc

type WalkFunc func(path string, info *FileInfo, depth int, ignores ignoreMatchers, err error) (error, ignoreMatchers)

Directories

Path Synopsis
cmd
pt

Jump to

Keyboard shortcuts

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