peco

package module
Version: v0.0.0-...-00d4233 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2014 License: MIT Imports: 15 Imported by: 0

README

peco

Simplistic interfacting filtering tool

Description

peco is based on percol. The idea is that percol was darn useful, but I wanted a tool that was a single binary. peco is written in Go, and as of this writing only implements the basic filtering feature (mainly because that's the only thing I use -- you're welcome to send me pull requests to make peco more compatible with percol).

peco can be a great tool to filter stuff like logs, process stats, find files, because unlike grep, you can type as you think and look through the current results.

Demo

Demos speak more than a thousand words! Here's me looking for a process on my mac. As you can see, you can page through your results, and you can keep changing the query:

optimized

Here's me trying to figure out which file to open:

optimized

When you combine tools like zsh, peco, and ghq, you can make managing/moving around your huge dev area a piece of cake! (this example doesn't use zsh functions so you can see what I'm doing)

optimized

Features

Search results are filtered as you type. This is great to drill down to the line you are looking for

Multiple terms turn the query into an "AND" query:

optimized

When you find that line that you want, press enter, and the resulting line is printed to stdout, which allows you to pipe it to other tools

Works on Windows!

I have been told that peco even works on windows :)

Installation

If you just want the command:

go install github.com/lestrrat/peco/cmd/peco/

If you want the source code:

go get github.com/lestrrat/peco

Usage

If you can read Japanese, here's one cool usage using ghq

Basically, you can define a simple function to easily move around your source code tree:

function peco-src () {
    local selected_dir=$(ghq list --full-path | peco --query "$LBUFFER")
    if [ -n "$selected_dir" ]; then
        BUFFER="cd ${selected_dir}"
        zle accept-line
    fi    
    zle clear-screen
}         
zle -N peco-src

Or to easily navigate godoc for your local stuff:

function peco-godoc() { 
    local selected_dir=$(ghq list --full-path | peco --query "$LBUFFER")
    if [ -n "$selected_dir" ]; then
        BUFFER="godoc ${selected_dir} | less"
        zle accept-line 
    fi 
    zle clear-screen 
}
    
zle -N peco-godoc 

Command Line Options

--help

Display a help message

--query

Specifies the default query to be used upon startup. This is useful for scripts and functions where you can figure out before hand what the most likely query string is.

--rcfile

Pass peco a configuration file, which currently must be a JSON file. If unspecified, it will read ~/.peco/config.json by default (if available)

Configuration File

By default configuration file in ~/.peco/config.json will be searched. You may also pass an arbitrary filename via the --rcfile option

Currently only keymaps are supported:

{
    "Keymap": {
        "C-p": "peco.SelectPrevious",
        "C-n": "peco.SelectNext"
    }
}

Available keys:

Name Notes
C-a ... C-z Control + whatever character
C-1 ... C-8 Control + 1..8
C-[
C-]
C-~
C-_
C-\\ Note that you need to escape the backslash
C-/
Esc
Tab
Insert
Delete
Home
End
Pgup
Pgdn
ArrowUp
ArrowDown
ArrowLeft
ArrowRight

Available actions

Name Notes
peco.ForwardChar Move caret forward 1 character
peco.BackwardChar Move caret backward 1 character
peco.ForwardWord Move caret forward 1 word
peco.BackwardWord Move caret backward 1 word
peco.BeginnigOfLine Move caret to the beginning of line
peco.EndOfLine Move caret to the end of line
peco.DeleteForwardChar Delete one character forward
peco.DeleteBackwardChar Delete one character backward
peco.DeleteForwardWord Delete one word forward
peco.DeleteBackwardWord Delete one word backward
peco.KillEndOfLine Delete the characters under the cursor until the end of the line
peco.DeleteAll Delete all entered characters
peco.SelectPreviousPage Jumps to previous page
peco.SelectNextPage Jumps to next page
peco.SelectPrevious Selects previous line
peco.SelectNext Selects next line
peco.Finish Exits from peco, with success status
peco.Cancel Exits from peco, with failure status

TODO

Test it. In doing so, we may change the repo structure

Implement all(?) of the original percol options

Notes

Obviously, kudos to the original percol: https://github.com/mooz/percol Much code stolen from https://github.com/mattn/gof

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTty

func IsTty() bool

func TtyReady

func TtyReady() error

func TtyTerm

func TtyTerm()

Types

type Config

type Config struct {
	Keymap Keymap `json:"Keymap"`
}

func NewConfig

func NewConfig() *Config

func (*Config) ReadFilename

func (c *Config) ReadFilename(filename string) error

type Ctx

type Ctx struct {
	ExitStatus int
	// contains filtered or unexported fields
}

Ctx contains all the important data. while you can easily access data in this struct from anwyehre, only do so via channels

func NewCtx

func NewCtx() *Ctx

func (*Ctx) AddWaitGroup

func (c *Ctx) AddWaitGroup()

func (*Ctx) Buffer

func (c *Ctx) Buffer() []Match

func (*Ctx) DrawCh

func (c *Ctx) DrawCh() chan []Match

func (*Ctx) DrawMatches

func (c *Ctx) DrawMatches(m []Match)

func (*Ctx) ExecQuery

func (c *Ctx) ExecQuery(v string)

func (*Ctx) Finish

func (c *Ctx) Finish()

func (*Ctx) LoopCh

func (c *Ctx) LoopCh() chan struct{}

func (*Ctx) NewFilter

func (c *Ctx) NewFilter() *Filter

func (*Ctx) NewInput

func (c *Ctx) NewInput() *Input

func (*Ctx) NewView

func (c *Ctx) NewView() *View

func (*Ctx) PagingCh

func (c *Ctx) PagingCh() chan PagingRequest

func (*Ctx) QueryCh

func (c *Ctx) QueryCh() chan string

func (*Ctx) ReadBuffer

func (c *Ctx) ReadBuffer(input io.Reader) error

func (*Ctx) ReadConfig

func (c *Ctx) ReadConfig(file string) error

func (*Ctx) Refresh

func (c *Ctx) Refresh()

func (*Ctx) ReleaseWaitGroup

func (c *Ctx) ReleaseWaitGroup()

func (*Ctx) Result

func (c *Ctx) Result() string

func (*Ctx) SetQuery

func (c *Ctx) SetQuery(q []rune)

func (*Ctx) Terminate

func (c *Ctx) Terminate()

func (*Ctx) WaitDone

func (c *Ctx) WaitDone()

type Filter

type Filter struct {
	*Ctx
}

func (*Filter) Loop

func (f *Filter) Loop()

type Input

type Input struct {
	*Ctx
}

func (*Input) Loop

func (i *Input) Loop()

type Keymap

type Keymap map[termbox.Key]KeymapHandler

func NewKeymap

func NewKeymap() Keymap

func (Keymap) Handler

func (km Keymap) Handler(k termbox.Key) KeymapHandler

func (Keymap) UnmarshalJSON

func (km Keymap) UnmarshalJSON(buf []byte) error

type KeymapHandler

type KeymapHandler func(*Input, termbox.Event)

type KeymapStringKey

type KeymapStringKey string

func (KeymapStringKey) ToKey

func (ksk KeymapStringKey) ToKey() (k termbox.Key, err error)

type Match

type Match struct {
	// contains filtered or unexported fields
}

type PagingRequest

type PagingRequest int
const (
	ToNextLine PagingRequest = iota
	ToNextPage
	ToPrevLine
	ToPrevPage
)

type View

type View struct {
	*Ctx
}

func (*View) Loop

func (u *View) Loop()

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL