Simplistic interactive filtering tool

Related tags

Command Line peco
Overview

peco

Simplistic interactive filtering tool

NOTE: If you are viewing this on GitHub, this document refers to the state of peco in whatever current branch you are viewing, not necessarily the state of a currently released version. Please make sure to checkout the Changes file for features and changes.

This README is long and comprehensive. Use the Table of Contents to navigate to the section that interests you. It has been placed at the bottom of the README file because of its length.

If you use peco, please consider sponsoring the authors of this project from the "Sponsor" button on the project page at https://github.com/peco/peco. Sponsorship plans start at $1 :)

Description

peco (pronounced peh-koh) is based on a python tool, percol. percol was darn useful, but I wanted a tool that was a single binary, and forget about python. peco is written in Go, and therefore you can just grab the binary releases and drop it in your $PATH.

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.

For basic usage, continue down below. For more cool elaborate usage samples, please see the wiki, and if you have any other tricks you want to share, please add to it!

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:

Executed ps -ef | peco, then the query root was typed. This shows all lines containing the word root

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

Executed find . -name '*.go' | peco (within camlistore repository), then the query camget was typed. This shows all lines including the word camget

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)

Executed cd $(ghq list --full-path | peco --query peco) to show all repositories containing the word peco, then to change directories into the one selected

Features

Incremental Search

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:

Executed ps aux | peco, then the query root app was typed. This shows all lines containing both root and app

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

Select Multiple Lines

You can select multiple lines! (this example uses C-Space)

Executed ls -l | peco, then used peco.ToggleSelection to select multiple lines

Select Range Of Lines

Not only can you select multiple lines one by one, you can select a range of lines (Note: The ToggleRangeMode action is not enabled by default. You need to put a custom key binding in your config file)

Executed ps -ef | peco, then used peco.ToggleRangeMode to select a range of lines

Select Filters

Different types of filters are available. Default is case-insensitive filter, so lines with any case will match. You can toggle between IgnoreCase, CaseSensitive, SmartCase, Regexp and Fuzzy filters.

The SmartCase filter uses case-insensitive matching when all of the queries are lower case, and case-sensitive matching otherwise.

The Regexp filter allows you to use any valid regular expression to match lines.

The Fuzzy filter allows you to find matches using partial patterns. For example, when searching for ALongString, you can enable the Fuzzy filter and search ALS to find it. The Fuzzy filter uses smart case search like the SmartCase filter.

Executed ps aux | peco, then typed google, which matches the Chrome.app under IgnoreCase filter type. When you change it to Regexp filter, this is no longer the case. But you can type (?i)google instead to toggle case-insensitive mode

Selectable Layout

As of v0.2.5, if you would rather not move your eyes off of the bottom of the screen, you can change the screen layout by either providing the --layout=bottom-up command line option, or set the Layout variable in your configuration file

Executed ps -ef | peco --layout=bottom-up to toggle inverted layout mode

Works on Windows!

I have been told that peco even works on windows :) Look ma! I'm not lying!

Showing peco running on Windows cmd.exe

Installation

Just want the binary?

Go to the releases page, find the version you want, and download the zip file. Unpack the zip file, and put the binary to somewhere you want (on UNIX-y systems, /usr/local/bin or the like). Make sure it has execution bits turned on. Yes, it is a single binary! You can put it anywhere you want :)

THIS IS THE RECOMMENDED WAY (except for macOS homebrew users)

macOS (Homebrew, Scarf)

If you're on macOS and want to use homebrew:

brew install peco

or with Scarf:

scarf install peco

Debian and Ubuntu based distributions (APT, Scarf)

There is an official Debian package that can be installed via APT:

apt install peco

or with Scarf:

scarf install peco

Void Linux (XBPS)

xbps-install -S peco

Arch Linux (AUR)

yay -S peco

Windows (Chocolatey NuGet Users)

There's a third-party peco package available for Chocolatey NuGet.

C:\> choco install peco

Building peco yourself

Make sure to clone the source code under $GOPATH (i.e. $GOPATH/src/github.com/peco/peco). This is required as the main binary refers to an internal package, which requires that the source code be located in the correct package location.

Navigate to the directory above, then run:

make build

This will do the following:

  1. Run go build to create releases/$VERSION_NUMBER/peco

You can copy the binary to somewhere in your $PATH, and it should just work.

The above installs the correct versions of peco's dependencies. Then build it:

go build cmd/peco/peco.go

This compiles a peco binary in the root of the cloned peco repository. Copy this file to an appropriate location.

go get IS NOT RECOMMENDED

Please DO NOT use go get to install this tool. It bypasses the developers' intention of controlling the dependency versioning.

Command Line Options

-h, --help

Display a help message

--version

Display the version of peco

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

--print-query

When exiting, prints out the query typed by the user as the first line of output. The query will be printed even if there are no matches, if the program is terminated normally (i.e. enter key). On the other hand, the query will NOT be printed if the user exits via a cancel (i.e. esc key).

--rcfile

Pass peco a configuration file, which currently must be a JSON file. If unspecified it will try a series of files by default. See Configuration File for the actual locations searched.

-b, --buffer-size

Limits the buffer size to num. This is an important feature when you are using peco against a possibly infinite stream, as it limits the number of lines that peco holds at any given time, preventing it from exhausting all the memory. By default the buffer size is unlimited.

--null

WARNING: EXPERIMENTAL. This feature will probably stay, but the option name may change in the future.

Changes how peco interprets incoming data. When this flag is set, you may insert NUL ('\0') characters in your input. Anything before the NUL character is treated as the string to be displayed by peco and is used for matching against user query. Anything after the NUL character is used as the "result": i.e., when peco is about to exit, it displays this string instead of the original string displayed.

Here's a simple example of how to use this feature

--initial-index

Specifies the initial line position upon start up. E.g. If you want to start out with the second line selected, set it to "1" (because the index is 0 based).

--initial-filter IgnoreCase|CaseSensitive|SmartCase|Regexp|Fuzzy

Specifies the initial filter to use upon start up. You should specify the name of the filter like IgnoreCase, CaseSensitive, SmartCase, Regexp and Fuzzy. Default is IgnoreCase.

--prompt

Specifies the query line's prompt string. When specified, takes precedence over the configuration file's Prompt section. The default value is QUERY>.

--layout top-down|bottom-up

Specifies the display layout. Default is top-down, where query prompt is at the top, followed by the list, then the system status message line. bottom-up changes this to the list first (displayed in reverse order), the query prompt, and then the system status message line.

For percol users, --layout=bottom-up is almost equivalent of --prompt-bottom --result-bottom-up.

--select-1

When specified and the input contains exactly 1 line, peco skips prompting you for a choice, and selects the only line in the input and immediately exits.

If there are multiple lines in the input, the usual selection view is displayed.

--on-cancel success|error

Specifies the exit status to use when the user cancels the query execution. For historical and back-compatibility reasons, the default is success, meaning if the user cancels the query, the exit status is 0. When you choose error, peco will exit with a non-zero value.

--selection-prefix string

When specified, peco uses the specified prefix instead of changing line color to indicate currently selected line(s). default is to use colors. This option is experimental.

--exec string

When specified, peco executes the specified external command (via shell), with peco's currently selected line(s) as its input from STDIN.

Upon exiting from the external command, the control goes back to peco where you can keep browsing your search buffer, and to possibly execute your external command repeatedly afterwards.

To exit out of peco when running in this mode, you must execute the Cancel command, usually the escape key.

Configuration File

peco by default consults a few locations for the config files.

  1. Location specified in --rcfile. If this doesn't exist, peco complains and exits
  2. $XDG_CONFIG_HOME/peco/config.json
  3. $HOME/.config/peco/config.json
  4. for each directory listed in $XDG_CONFIG_DIRS, $DIR/peco/config.json
  5. If all else fails, $HOME/.peco/config.json

Below are configuration sections that you may specify in your config file:

Global

Global configurations that change the global behavior.

Prompt

You can change the query line's prompt, which is QUERY> by default.

{
    "Prompt": "[peco]"
}

InitialMatcher

InitialMatcher has been deprecated. Please use InitialFilter instead.

InitialFilter

Specifies the filter name to start peco with. You should specify the name of the filter, such as IgnoreCase, CaseSensitive, SmartCase, Regexp and Fuzzy.

StickySelection

{
    "StickySelection": true
}

StickySelection allows selections to persist even between changes to the query. For example, when you set this to true you can select a few lines, type in a new query, select those lines, and then delete the query. The result is all the lines that you selected before and after the modification to the query are left intact.

Default value for StickySelection is false.

OnCancel

{
    "OnCancel": "error"
}

OnCancel is equivalent to --on-cancel command line option.

MaxScanBufferSize

{
    "MaxScanBufferSize": 256
}

Controls the buffer sized (in kilobytes) used by bufio.Scanner, which is responsible for reading the input lines. If you believe that your input has very long lines that prohibit peco from reading them, try increasing this number.

The same time, the default MaxScanBuferSize is 256kb.

Keymaps

Example:

{
    "Keymap": {
        "M-v": "peco.ScrollPageUp",
        "C-v": "peco.ScrollPageDown",
        "C-x,C-c": "peco.Cancel"
    }
}

Key sequences

As of v0.2.0, you can use a list of keys (separated by comma) to register an action that is associated with a key sequence (instead of a single key). Please note that if there is a conflict in the key map, the longest sequence always wins. So In the above example, if you add another sequence, say, C-x,C-c,C-c, then the above peco.Cancel will never be invoked.

Combined actions

As of v0.2.1, you can create custom combined actions. For example, if you find yourself repeatedly needing to select 4 lines out of the list, you may want to define your own action like this:

{
    "Action": {
        "foo.SelectFour": [
            "peco.ToggleRangeMode",
            "peco.SelectDown",
            "peco.SelectDown",
            "peco.SelectDown",
            "peco.ToggleRangeMode"
        ]
    },
    "Keymap": {
        "M-f": "foo.SelectFour"
    }
}

This creates a new combined action foo.SelectFour (the format of the name is totally arbitrary, I just like to put namespaces), and assigns that action to M-f. When it's fired, it toggles the range selection mode and highlights 4 lines, and then goes back to waiting for your input.

As a similar example, a common idiom in emacs is that C-c C-c means "take the contents of this buffer and accept it", whatever that means. This adds exactly that keybinding:

{
    "Action": {
        "selectAllAndFinish": [
            "peco.SelectAll",
            "peco.Finish"
        ]
    },
    "Keymap": {
        "C-c,C-c": "selectAllAndFinish"
    }
}

Available keys

Since v0.1.8, in addition to values below, you may put a M- prefix on any key item to use Alt/Option key as a mask.

Name Notes
C-a ... C-z Control + whatever character
C-2 ... C-8 Control + 2..8
C-[
C-]
C-~
C-_
C-\\ Note that you need to escape the backslash
C-/
C-Space
F1 ... F12
Esc
Tab
Enter
Insert
Delete
BS
BS2
Home
End
Pgup
Pgdn
ArrowUp
ArrowDown
ArrowLeft
ArrowRight
MouseLeft
MouseMiddle
MouseRight

Key workarounds

Some keys just... don't map correctly / too easily for various reasons. Here, we'll list possible workarounds for key sequences that are often asked for:

You want this Use this instead Notes
Shift+Tab M-[,Z Verified on macOS

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.BackToInitialFilter Switch to first filter in the list
peco.BeginningOfLine Move caret to the beginning of line
peco.EndOfLine Move caret to the end of line
peco.EndOfFile Delete one character forward, otherwise exit from peco with failure status
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.InvertSelection Inverts the selected lines
peco.KillBeginningOfLine Delete the characters under the cursor backward until the beginning of the line
peco.KillEndOfLine Delete the characters under the cursor until the end of the line
peco.DeleteAll Delete all entered characters
peco.RefreshScreen Redraws the screen. Note that this effectively re-runs your query
peco.SelectPreviousPage (DEPRECATED) Alias to ScrollPageUp
peco.SelectNextPage (DEPRECATED) Alias to ScrollPageDown
peco.ScrollPageDown Moves the selected line cursor for an entire page, downwards
peco.ScrollPageUp Moves the selected line cursor for an entire page, upwards
peco.SelectUp Moves the selected line cursor to one line above
peco.SelectDown Moves the selected line cursor to one line below
peco.SelectPrevious (DEPRECATED) Alias to SelectUp
peco.SelectNext (DEPRECATED) Alias to SelectDown
peco.ScrollLeft Scrolls the screen to the left
peco.ScrollRight Scrolls the screen to the right
peco.ScrollFirstItem Scrolls to the first item (in the entire buffer, not the current screen)
peco.ScrollLastItem Scrolls to the last item (in the entire buffer, not the current screen)
peco.ToggleSelection Selects the current line, and saves it
peco.ToggleSelectionAndSelectNext Selects the current line, saves it, and proceeds to the next line
peco.ToggleSingleKeyJump Enables SingleKeyJump mode a.k.a. "hit-a-hint"
peco.SelectNone Remove all saved selections
peco.SelectAll Selects the all line, and save it
peco.SelectVisible Selects the all visible line, and save it
peco.ToggleSelectMode (DEPRECATED) Alias to ToggleRangeMode
peco.CancelSelectMode (DEPRECATED) Alias to CancelRangeMode
peco.ToggleQuery Toggle list between filterd by query and not filterd.
peco.ToggleRangeMode Start selecting by range, or append selecting range to selections
peco.CancelRangeMode Finish selecting by range and cancel range selection
peco.RotateMatcher (DEPRECATED) Use peco.RotateFilter
peco.RotateFilter Rotate between filters (by default, ignore-case/no-ignore-case)
peco.Finish Exits from peco with success status
peco.Cancel Exits from peco with failure status, or cancel select mode

Default Keymap

Note: If in case below keymap seems wrong, check the source code in keymap.go (look for NewKeymap).

Key Action
Esc peco.Cancel
C-c peco.Cancel
Enter peco.Finish
C-f peco.ForwardChar
C-a peco.BeginningOfLine
C-b peco.BackwardChar
C-d peco.DeleteForwardChar
C-e peco.EndOfLine
C-k peco.KillEndOfLine
C-u peco.KillBeginningOfLine
BS peco.DeleteBackwardChar
C-8 peco.DeleteBackwardChar
C-w peco.DeleteBackwardWord
C-g peco.SelectNone
C-n peco.SelectDown
C-p peco.SelectUp
C-r peco.RotateFilter
C-t peco.ToggleQuery
C-Space peco.ToggleSelectionAndSelectNext
ArrowUp peco.SelectUp
ArrowDown peco.SelectDown
ArrowLeft peco.ScrollPageUp
ArrowRight peco.ScrollPageDown

Styles

For now, styles of following 5 items can be customized in config.json.

{
    "Style": {
        "Basic": ["on_default", "default"],
        "SavedSelection": ["bold", "on_yellow", "white"],
        "Selected": ["underline", "on_cyan", "black"],
        "Query": ["yellow", "bold"],
        "Matched": ["red", "on_blue"]
    }
}
  • Basic for not selected lines
  • SavedSelection for lines of saved selection
  • Selected for a currently selecting line
  • Query for a query line
  • Matched for a query matched word

Foreground Colors

  • "black" for termbox.ColorBlack
  • "red" for termbox.ColorRed
  • "green" for termbox.ColorGreen
  • "yellow" for termbox.ColorYellow
  • "blue" for termbox.ColorBlue
  • "magenta" for termbox.ColorMagenta
  • "cyan" for termbox.ColorCyan
  • "white" for termbox.ColorWhite
  • "0"-"255" for 256color (Use256Color must be enabled)

Background Colors

  • "on_black" for termbox.ColorBlack
  • "on_red" for termbox.ColorRed
  • "on_green" for termbox.ColorGreen
  • "on_yellow" for termbox.ColorYellow
  • "on_blue" for termbox.ColorBlue
  • "on_magenta" for termbox.ColorMagenta
  • "on_cyan" for termbox.ColorCyan
  • "on_white" for termbox.ColorWhite
  • "on_0"-"on_255" for 256color (Use256Color must be enabled)

Attributes

  • "bold" for fg: termbox.AttrBold
  • "underline" for fg: termbox.AttrUnderline
  • "reverse" for fg: termbox.AttrReverse
  • "on_bold" for bg: termbox.AttrBold (this attribute actually makes the background blink on some platforms/environments, e.g. linux console, xterm...)

CustomFilter

This is an experimental feature. Please note that some details of this specification may change

By default peco comes with IgnoreCase, CaseSensitive, SmartCase, Regexp and Fuzzy filters, but since v0.1.3, it is possible to create your own custom filter.

The filter will be executed via Command.Run() as an external process, and it will be passed the query values in the command line, and the original unaltered buffer is passed via os.Stdin. Your filter must perform the matching, and print out to os.Stdout matched lines. Your filter MAY be called multiple times if the buffer given to peco is big enough. See BufferThreshold below.

Note that currently there is no way for the custom filter to specify where in the line the match occurred, so matched portions in the string WILL NOT BE HIGHLIGHTED.

The filter does not need to be a go program. It can be a perl/ruby/python/bash script, or anything else that is executable.

Once you have a filter, you must specify how the matcher is spawned:

{
    "CustomFilter": {
        "MyFilter": {
            "Cmd": "/path/to/my-matcher",
            "Args": [ "$QUERY" ],
            "BufferThreshold": 100
        }
    }
}

Cmd specifies the command name. This must be searcheable via exec.LookPath.

Elements in the Args section are string keys to array of program arguments. The special token $QUERY will be replaced with the unaltered query as the user typed in (i.e. multiple-word queries will be passed as a single string). You may pass in any other arguments in this array. If you omit this in your config, a default value of []string{"$QUERY"} will be used

BufferThreshold specifies that the filter command should be invoked when peco has this many lines to process in the buffer. For example, if you are using peco against a 1000-line input, and your BufferThreshold is 100 (which is the default), then your filter will be invoked 10 times. For obvious reasons, the larger this threshold is, the faster the overall performance will be, but the longer you will have to wait to see the filter results.

You may specify as many filters as you like in the CustomFilter section.

Examples

Layout

See --layout.

SingleKeyJump

{
  "SingleKeyJump": {
    "ShowPrefix": true
  }
}

SelectionPrefix

SelectionPrefix is equivalent to using --selection-prefix in the command line.

{
  "SelectionPrefix": ">"
}

Use256Color

Boolean value that determines whether or not to use 256color. The default is false.

Note: This has no effect on Windows because Windows console does not support extra color modes.

{
    "Use256Color": true
}

FAQ

Does peco work on (msys2|cygwin)?

No. https://github.com/peco/peco/issues/336#issuecomment-243939696 (Updated Feb 23, 2017: "Maybe" on cygwin https://github.com/peco/peco/issues/336#issuecomment-281912949)

Non-latin fonts (e.g. Japanese) look weird on my Windows machine...?

Are you using raster fonts? https://github.com/peco/peco/issues/341

Seeing escape sequences [200~ and [201~ when pasting text?

Disable bracketed paste mode. https://github.com/peco/peco/issues/417

Hacking

First, fork this repo, and get your clone locally.

  1. Make sure you have go installed, with GOPATH appropriately set
  2. Make sure you have make installed
  3. Run make installdeps (You only need to do this once)

To test, run

make test

To build, run

make build

This will create a peco binary in $(RELEASE_DIR)/peco_$(GOOS)_$(GOARCH)/peco$(SUFFIX). Or, of course, you can just run

go build cmd/peco/peco.go

which will create the binary in the local directory.

TODO

Unit test it.

AUTHORS

  • Daisuke Maki (lestrrat)
  • mattn
  • syohex

CONTRIBUTORS

  • HIROSE Masaaki
  • Joel Segerlind
  • Lukas Lueg
  • Mitsuoka Mimura
  • Ryota Arai
  • Shinya Ohyanagi
  • Takashi Kokubun
  • Yuya Takeyama
  • cho45
  • cubicdaiya
  • kei_q
  • negipo
  • sona_tar
  • sugyan
  • swdyh
  • MURAOKA Taro (kaoriya/koron), for aho-corasick search
  • taichi, for the gif working on Windows
  • uobikiemukot
  • Samuel Lemaitre
  • Yousuke Ushiki
  • Linda_pp
  • Tomohiro Nishimura (Sixeight)
  • Naruki Tanabe (narugit)

Notes

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

Table of Contents

Comments
  • go's cross compilation fails when we use os/user

    go's cross compilation fails when we use os/user

    This issue is basically a reminder for us so we can remember this later.

    See #101 . Basically:

    • Go currently does not support cross compilation for cgo
    • os/user for darwin and linux uses cgo for getpwuid_r
    • Using wercker to do cross-compilation basically just... fails.
    • But instead of failure, we get a half-baked binary.

    Currently I don't see any way to overcome this. Maybe rewrite glibc in go (HA HA!).

    opened by lestrrat 39
  • brewed peco can't resolve ~/.peco/config.json

    brewed peco can't resolve ~/.peco/config.json

    homebrewでinstallしたpecoだと、~/.peco/config.json を自動で読みに行ってくれないようです。 バージョンは v0.1.9です。

    % peco --rcfile ~/.peco/config.json 
    

    のように明示的に指定すれば大丈夫でした。

    また、

    % go get github.com/peco/peco/cmd/peco
    % go build cmd/peco/peco.go
    

    などとした場合は、~/.peco/config.json は自動で読みにいってくれてちゃんと動いていますので、それで使っています。

    以下同様の報告です。

    • https://twitter.com/glidenote/status/480892276760014848
    • https://twitter.com/Echos/status/481794095854010368
    opened by Songmu 29
  • Option for placing query line at bottom of view rather than top

    Option for placing query line at bottom of view rather than top

    I use peco as a replacement for my shell's ctrl+r history search. And most of the time in any shell, the prompt will be at the bottom of the window as there's preview commands and output above.

    Hence an option to have the query appear at the bottom instead of the top, would make it nicer to use as shell history replacement, cause your eyes wouldn't need to travel from the bottom to the top of the window.

    Obviously this would also mean the result list would need to be reversed.

    And that's my feature request :)

    opened by jimeh 26
  • Implement hit-a-hint

    Implement hit-a-hint

    Second take of #261

    • "@" toggles "SingleKeyJump" mode
    • list of hot keys are displayed to the left
    • selecting the key allows you to jump to the line, and peco exits by selecting that line
    opened by lestrrat 21
  • Macports | Peco hang

    Macports | Peco hang

    When using peco in combination with Macports, peco hangs with the following:

    port installed | peco

    I'm not sure what is special about the output from port installed that causes this hang; I don't see any special characters or 'weird' line endings.

    opened by cuyler 21
  • Terminal freezes when running my custom action

    Terminal freezes when running my custom action

    What is the peco version, OS, architecture?

    • peco version - 0.4.2
    • OS - RHEL 6.6
    • Terminal - xterm
    • Shell - tcsh
    • Using in tmux master branch build

    Abstract

    My custom action causes peco to freeze and in the process of killing the stuck process, I also lose my terminal cursor. So then I eventually need to kill that terminal too.

    Discussion

    I have this custom action named my.ToggleSelectionInAboveLine, and I have bound it to C-u,C-Space.

    When I use the C-u,S-Space binding, peco freezes, and I need to use kill -9 to kill it from another terminal. Then the terminal recovers, but I do not see my regular cursor in the terminal any more!

    So there are 2 issues:

    1. `peco is freezing due to this action:

          "my.ToggleSelectionInAboveLine": [
              "peco.SelectUp",
              "peco.ToggleSelectionAndSelectNext"
          ],
      
    2. After peco is killed, I lose the cursor in my terminal.

      This is what a selected terminal (pane, in tmux) looks like normally:

      • Note that the upper terminal is selected and you can see the cursor in that

      image

      The bottom terminal is where I had to kill the peco process. Now even though that is selected, you see no cursor in there.

      image

    My config

    opened by kaushalmodi 19
  • Allow toggling the filter on/off (was

    Allow toggling the filter on/off (was "suggestion: unfilter lines!")

    i found that peco almost works very nicely as a file viewer. i can open a single file, filter the lines, spot what i'm interested in... but then i'm stuck.

    it would be really nice to be able to clear the filter but to leave the cursor on a selected line. the surrounding lines would then be visible. i admit it's not quite in the spirit of what peco is trying do, but possibly it's a really simple addition that wouldn't affect other functionality?

    my apologies if this is already possible... i searched, but couldn't find it...

    jack

    opened by jack99999 19
  • Support bold background attribute

    Support bold background attribute

    termbox sends:

    • fg: AttributeBold -> SGR:Bold
    • fg: AttributeUnderline -> SGR:Underline
    • fg: AttributeReverse -> SGR: Reverse
    • bg: AttributeBold -> SGR: Blink

    But there is no style option for bg: AttributeBold in peco. This pull reqeust enables to set bold background attribute.

    opened by uobikiemukot 19
  • Make --select-1 work with --query

    Make --select-1 work with --query

    What is the peco version, OS, architecture?

    • peco 0.4.9 (built from master today using commit 766fdd7)
    • RHEL 6.6 64-bit

    Abstract

    The --select-1 option works, but not when --query is specified too.

    Discussion

    This works:

    echo "a" | \peco --select-1
    

    This does not:

    echo "a\nb" | \peco --select-1 --query=a
    

    Here is one of the example use cases of the latter:

    # tcsh alias (because bash is not an option at work)
    alias pcd 'dirs | peco --select-1 --query=\!*  | awk '"'"'{print $2}'"'"' | xsel -ip; cd `xsel -op`'
    cd /home/$USER/foo
    cd /tmp
    pcd foo
    

    Above, if peco --query=foo filters down to only one result, doing pcd foo will save me one key-stroke (Enter) if --select-1 worked with --query.

    opened by kaushalmodi 17
  • Add finish command with exit status code 101 and 102.

    Add finish command with exit status code 101 and 102.

    Zawやemacsのhelm, anythingやvimのuniteのように、候補を絞った後、選択する際のキーによってactionを変えたい時のために、終了statusを0以外にするfinish commandを作成しました。

    コマンドの使用例

    以下のようなzshの関数を作ります。

    function peco-select-history() {
        local tac
        BUFFER=$(history -n -r 1 | \
            peco --query "$LBUFFER")
        if [[ "$?" == "0" ]]; then
            zle accept-line
        else
            CURSOR=$#BUFFER
        fi
        zle clear-screen
    }
    

    また、以下のような設定をしておきます。

    {
        "Keymap": {
            "C-j": "peco.FinishWith101"}
    }
    

    この状態でpeco-select-historyを実行し、絞り込みを選択する際にRetで選択すると、履歴をそのまま実行。 C-jで選択すると、現在のshellに表示して、編集可能な状態で終了します。

    opened by kenbeese 16
  • peco.Cancel action

    peco.Cancel action

    I suppose peco.Cancel should work like sending SIGINT. (peco.Cancel should kills processes in same session group.) Now successive command is executed if peco.Cancel is executed. For example,

    % ls -l | peco | xargs echo "hoge"
    hoge
    

    On the other hand, cancel command of percol(C-c) works like sending SIGINT.

    % ls -l |percol| xargs echo "hoge"
    # Nothing is shown
    
    opened by syohex 16
  • --exit-0

    --exit-0

    I'd like to request a new command-line option: --exit-0.

    --select-1 means "select the first item and immediately exit if the input contains only 1 item". Likewise, --exit-0 would mean "immediately exit if the input is empty" (i.e. "contains 0 items").

    I also think the exit status should be non-zero in this case.

    The end goal is to be able to write something like this:

    fd "$filename" | peco --exit-0 || {
    
        echo >/dev/stderr 'Not found.'
        exit 1
    }
    
    opened by tfga 4
  • Custom actions feature request

    Custom actions feature request

    I'm using peco for a while and it seems to me a very great tool. Apart from that there is a way to improve it dramatically. Currently there are available only built-in actions and those actions could be called with hotkeys. It would be great to have a separate section in the config file to setup hotkey to execute shortcut action with selected items - for example open selected item in text editor or cd into directory. Take a look at an example of such a config: { "Execute": { "foo.OpenEditor": [ "micro $result" ] }, "Keymap": { "M-e": "foo.OpenEditor" } } If I press Ctrl+e peco will open selected item in micro text editor just by running "micro $selected_item"

    opened by artemijan 0
  • Sometimes peco freezes.

    Sometimes peco freezes.

    What is the peco version, OS, architecture?

    % peco --version
    peco version v0.5.1
    % cat /etc/*release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=20.04
    DISTRIB_CODENAME=focal
    DISTRIB_DESCRIPTION="Ubuntu 20.04.4 LTS"
    NAME="Ubuntu"
    VERSION="20.04.4 LTS (Focal Fossa)"
    ID=ubuntu
    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 20.04.4 LTS"
    VERSION_ID="20.04"
    HOME_URL="https://www.ubuntu.com/"
    SUPPORT_URL="https://help.ubuntu.com/"
    BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
    PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
    VERSION_CODENAME=focal
    UBUNTU_CODENAME=focal
    MOZART [~/dev/tmp/20220329/peco-freeze]
    % uname -m
    x86_64
    % zsh --version
    zsh 5.8 (x86_64-ubuntu-linux-gnu)
    % tmux -V
    tmux 3.0a
    
    

    Abstract

    It sometimes freezes when I run peco via a command created in zsh, it won't accept Ctr-C, etc.

    Reproduction

    I am running peco via Ctr-s as follows. (I put ">& out" which I don't usually set to get a stack trace)

    function peco-select-shortcut(){
        LBUFFER+=$( \
          cat ~/dotfiles/pecommand.txt | \
          grep -v -e '^\s*#' -e '^$' | \
          peco --prompt "commands>" >& out | \
          sed -e 's/#.*$//' \
        )
        CURSOR=$#LBUFFER
        zle reset-prompt
    }
    
    zle -N peco-select-shortcut
    bindkey '^s' peco-select-shortcut
    
    % cat ~/dotfiles/pecommand.txt
    ls
    

    When I run the above registered Ctr-s many times, it sometimes freezes completely.

    スクリーンショット 2022-03-29 17 18 31

    The log of kill -ABRT pid at that time is as follows.

    SIGABRT: abort
    PC=0x4544b3 m=1 sigcode=0
    
    goroutine 0 [idle]:
    runtime.futex(0x6a89d8, 0x0, 0xc42003dec0, 0x0, 0xc400000000, 0x454146, 0x3c, 0x0, 0xc42003df08, 0x40d810, ...)
            /usr/lib/go-1.8/src/runtime/sys_linux_amd64.s:426 +0x23
    runtime.futexsleep(0x6a89d8, 0x0, 0xdf8475800)
            /usr/lib/go-1.8/src/runtime/os_linux.go:62 +0xd7
    runtime.notetsleep_internal(0x6a89d8, 0xdf8475800, 0x0)
            /usr/lib/go-1.8/src/runtime/lock_futex.go:174 +0xd0
    runtime.notetsleep(0x6a89d8, 0xdf8475800, 0x1)
            /usr/lib/go-1.8/src/runtime/lock_futex.go:194 +0x56
    runtime.sysmon()
            /usr/lib/go-1.8/src/runtime/proc.go:3805 +0x135
    runtime.mstart1()
            /usr/lib/go-1.8/src/runtime/proc.go:1179 +0x11e
    runtime.mstart()
            /usr/lib/go-1.8/src/runtime/proc.go:1149 +0x64
    
    goroutine 1 [chan send]:
    github.com/peco/peco.(*Termbox).Close(0xc42000a8e0, 0x690b60, 0xc420012f00)
            github.com/peco/peco/screen.go:32 +0x43
    github.com/peco/peco.(*Peco).Run(0xc420072700, 0x690b60, 0xc420012f00, 0x68fb20, 0x6c3028)
            github.com/peco/peco/peco.go:404 +0x504
    main._main(0x0)
            github.com/peco/peco/cmd/peco/peco.go:36 +0xdb
    main.main()
            github.com/peco/peco/cmd/peco/peco.go:22 +0x3e
    
    goroutine 5 [syscall]:
    os/signal.signal_recv(0x6901e0)
            /usr/lib/go-1.8/src/runtime/sigqueue.go:116 +0x104
    os/signal.loop()
            /usr/lib/go-1.8/src/os/signal/signal_unix.go:22 +0x22
    created by os/signal.init.1
            /usr/lib/go-1.8/src/os/signal/signal_unix.go:28 +0x41
    
    goroutine 7 [select, locked to thread]:
    runtime.gopark(0x5d2ba8, 0x0, 0x5c7f68, 0x6, 0x18, 0x2)
            /usr/lib/go-1.8/src/runtime/proc.go:271 +0x13a
    runtime.selectgoImpl(0xc42011cf50, 0x0, 0x18)
            /usr/lib/go-1.8/src/runtime/select.go:423 +0x1364
    runtime.selectgo(0xc42011cf50)
            /usr/lib/go-1.8/src/runtime/select.go:238 +0x1c
    runtime.ensureSigM.func1()
            /usr/lib/go-1.8/src/runtime/signal_unix.go:434 +0x2dd
    runtime.goexit()
            /usr/lib/go-1.8/src/runtime/asm_amd64.s:2197 +0x1
    
    goroutine 23 [select]:
    github.com/nsf/termbox-go.Init.func1()
            github.com/nsf/termbox-go/api.go:93 +0x37c
    created by github.com/nsf/termbox-go.Init
            github.com/nsf/termbox-go/api.go:105 +0x5ce
    
    goroutine 25 [chan send]:
    github.com/peco/peco.(*Termbox).PollEvent.func2(0xc4200ce300, 0x690b60, 0xc420012f00, 0xc42000a8e0)
            github.com/peco/peco/screen.go:88 +0xf2
    created by github.com/peco/peco.(*Termbox).PollEvent
            github.com/peco/peco/screen.go:100 +0xba
    
    rax    0xfffffffffffffffc
    rbx    0x0
    rcx    0x4544b3
    rdx    0x0
    rdi    0x6a89d8
    rsi    0x0
    rbp    0xc42003ded0
    rsp    0xc42003de88
    r8     0x0
    r9     0x0
    r10    0xc42003dec0
    r11    0x246
    r12    0x42be10
    r13    0x34
    r14    0x0
    r15    0xf3
    rip    0x4544b3
    rflags 0x246
    cs     0x33
    fs     0x0
    gs     0x0
    

    (Please be specific. Include code, pseudocode, screen captures if you can)

    opened by pocari 4
  • Use peco as a drop-in replacement of percol.

    Use peco as a drop-in replacement of percol.

    Currently, I've forked and add some enhancements to ariadne. See the following screenshot, which can give you a preliminary impression about the specific effect I want to achieve:

    image

    Although I am rather satisfied with ariadne, its underlying library percol has ceased maintenance and the logic used by percol is very quirky and strange to me. So it's difficult for me to further customize and enhance ariadne. This is the motivation I want to reimplement it with a more advanced, modern, and actively maintained curses-supporting TUI framework library.

    I also learned that peco is based on percol, so I want to know whether can I use peco as a drop-in replacement of percol, especially, how to adapt the configuration of percol for peco.

    Regards, HY

    opened by hongyi-zhao 0
  • Custom escape sequences for key bindings

    Custom escape sequences for key bindings

    What is the peco version, OS, architecture?

    • Peco version: v0.5.10
    • OS: Arch Linux
    • Architecture: x64

    Abstract

    I need to be able to set a custom escape sequences to a command. Common keys such as Ctrl + LeftArrow aren't working for me. Even after setting C-ArrowLeft in ~/.config/peco/config.json, I still get [1;5D printed instead.

    Discussion

    I'm giving Peco a shot as I saw it in Arch Linux's home page one day, and wondered what it was.

    My escape sequences are setup as http://www.leonerd.org.uk/hacks/fixterms/, which is supported by e.g. WezTerm, Kitty, Tmux.

    I don't see a way of using custom escape sequences in Peco however. The keys I need and their escape sequences are:

    • Ctrl + LeftArrow -> ^[[1;5C
    • Ctrl + RightArrow -> ^[[1;5D
    • Home -> ^[[H
    • End -> ^[[F
    • Ctrl + Delete -> ^[[127;5u
    • Ctrl + Backspace -> ^[[3;5~

    I would like a way to map some arbitrary escape sequence to a key. This is supported by say terminal emulators, Readline, Zsh.

    opened by stevenxxiu 0
  • HELP WANTED: migrate from termbox-go to tcell

    HELP WANTED: migrate from termbox-go to tcell

    Many of the recent issues seem to be stemming from termbox-go, which isn't being actively maintained anymore. We really need to migrate the underlying code from termbox-go to something else, presumably tcell, but I haven't been able to find the time and/or motivation to do this.

    If you are up for it, it would help us immensely if you can swap the underlying library to tcell.

    (NOTE: Yes, I know the code is horrible.)

    opened by lestrrat 0
Releases(v0.5.10)
Owner
null
Interactive cli tool for HTTP inspection

Wuzz command line arguments are similar to cURL's arguments, so it can be used to inspect/modify requests copied from the browser's network inspector with the "copy as cURL" feature.

Adam Tauber 10.1k Sep 27, 2022
An interactive command-line tool to manage your environments

goto An interactive command-line tool to manage your environments Overview You always need to login to some Linux machine or connect to a MySQL instan

Lucien 10 Jul 11, 2022
Abacus is a simple interactive calculator CLI

Abacus is a simple interactive calculator CLI with support for variables, comparison checks, and math functions abacus -

Viktor Danov 33 Sep 15, 2022
🔥 [WIP] Interactive Jira Command Line

JiraCLI Interactive Jira CLI ?? This project is still a work in progress ?? This tool mostly focuses on issue search and navigation at the moment. How

Ankit Pokhrel 2.1k Sep 14, 2022
Building powerful interactive prompts in Go, inspired by python-prompt-toolkit.

go-prompt A library for building powerful interactive prompts inspired by python-prompt-toolkit, making it easier to build cross-platform command line

Masashi Shibata 4.6k Sep 17, 2022
Terminal UI library with rich, interactive widgets — written in Golang

Rich Interactive Widgets for Terminal UIs This Go package provides commonly needed components for terminal based user interfaces. Among these componen

rivo 7.4k Sep 21, 2022
A golang library for building interactive prompts with full support for windows and posix terminals.

Survey A library for building interactive prompts on terminals supporting ANSI escape sequences. package main import ( "fmt" "github.com/Alec

Alec Aivazis 3.3k Sep 21, 2022
Interactive prompt for command-line applications

promptui Interactive prompt for command-line applications. We built Promptui because we wanted to make it easy and fun to explore cloud services with

Manifold 5.1k Sep 20, 2022
Build an interactive CLI application with Go, Cobra and promptui. Video tutorial available on the Div Rhino YouTube channel.

Build an interactive CLI app with Go, Cobra and promptui Text tutorial: https://divrhino.com/articles/build-interactive-cli-app-with-go-cobra-promptui

Div Rhino Dev 15 Sep 17, 2022
Interactive CLI helper for creating git branches with JIRA Links and some text

bb (better-branch) Interactive CLI helper for creating git branches with JIRA Links and some text Still in development? Yes How it works? This tiny ut

Eugene Uvarov 3 Aug 18, 2022
Interactive prompt to set and push a semver tag

cutver For when you know what version to tag, and you want to cut a release in the annotated tag format. Installation go install github.com/roryq/cutv

Rory Quinn 7 Oct 11, 2021
🧨 Interactive Process Killer CLI made with Go!

proc-manager is an interactive CLI to kill processes made with Go, currently supports Linux, Mac OS X, Solaris, and Windows.

Aykut 21 Sep 19, 2022
Generate an interactive, autocompleting shell for any Cobra CLI

cobra-shell Description Leverages the Cobra completion API to generate an interactive shell for any Cobra CLI, powered by go-prompt. On-the-fly autoco

Brian Strauch 29 Aug 31, 2022
The missing git branch --interactive

git branch-i I got cross that there's no git branch --interactive, so I made this. It's a very (very) simple curses-mode git branch/git checkout alter

Joel Auterson 3 Dec 17, 2021
An interactive shell for go application

goshell An interactive shell for go application in normal mode ctrl-c break exec

null 1 Aug 4, 2022
A simple CLI based rock-paper-scissors game created in GO with interactive shell prompt.

rock-paper-scissors A simple CLI (Command Line Interface) based rock-paper-scissors game with interactive shell prompt. Language Download Grab a binar

Saif Shahriar 0 Jul 17, 2022
A command line tool that builds and (re)starts your web application everytime you save a Go or template fileA command line tool that builds and (re)starts your web application everytime you save a Go or template file

# Fresh Fresh is a command line tool that builds and (re)starts your web application everytime you save a Go or template file. If the web framework yo

null 0 Nov 22, 2021
fofax is a fofa query tool written in go, positioned as a command-line tool and characterized by simplicity and speed.

fofaX 0x00 Introduction fofax is a fofa query tool written in go, positioned as

null 461 Sep 24, 2022
Nebula Diagnosis CLI Tool is an information diagnosis cli tool for the nebula service and the node to which the service belongs.

Nebula Diagnosis CLI Tool is an information diagnosis cli tool for the nebula service and the node to which the service belongs.

Katz 1 Jan 12, 2022