Git Product home page Git Product logo

percol's Introduction

percol

                                __
    ____  ___  ______________  / /
   / __ \/ _ \/ ___/ ___/ __ \/ /
  / /_/ /  __/ /  / /__/ /_/ / /
 / .___/\___/_/   \___/\____/_/
/_/

percol adds flavor of interactive selection to the traditional pipe concept on UNIX.

What's this

optimized

percol is an interactive grep tool in your terminal. percol

  1. receives input lines from stdin or a file,
  2. lists up the input lines,
  3. waits for your input that filter/select the line(s),
  4. and finally outputs the selected line(s) to stdout.

Since percol just filters the input and output the result to stdout, it can be used in command-chains with | in your shell (UNIX philosophy!).

Features

  • Efficient: With lazy loads of input lines and query caching, percol handles huge inputs efficiently.
  • Customizable: Through configuration file (rc.py), percol's behavior including prompts, keymaps, and color schemes can be heavily customizable.
  • Migemo support: By supporting C/Migemo, percol filters Japanese inputs blazingly fast.

Related projects

Installation

percol currently supports only Python 2.x.

PyPI

$ sudo pip install percol

Manual

First, clone percol repository and go into the directory.

$ git clone git://github.com/mooz/percol.git
$ cd percol

Then, run a command below.

$ sudo python setup.py install

If you don't have a root permission (or don't wanna install percol with sudo), try next one.

$ python setup.py install --prefix=~/.local
$ export PATH=~/.local/bin:$PATH

Usage

Specifying a filename.

$ percol /var/log/syslog

Specifying a redirection.

$ ps aux | percol

Example

Interactive pgrep / pkill

Here is an interactive version of pgrep,

$ ps aux | percol | awk '{ print $2 }'

and here is an interactive version of pkill.

$ ps aux | percol | awk '{ print $2 }' | xargs kill

For zsh users, command versions are here (ppkill accepts options like -9).

function ppgrep() {
    if [[ $1 == "" ]]; then
        PERCOL=percol
    else
        PERCOL="percol --query $1"
    fi
    ps aux | eval $PERCOL | awk '{ print $2 }'
}

function ppkill() {
    if [[ $1 =~ "^-" ]]; then
        QUERY=""            # options only
    else
        QUERY=$1            # with a query
        [[ $# > 0 ]] && shift
    fi
    ppgrep $QUERY | xargs kill $*
}

zsh history search

In your .zshrc, put the lines below.

function exists { which $1 &> /dev/null }

if exists percol; then
    function percol_select_history() {
        local tac
        exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } }
        BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
        CURSOR=$#BUFFER         # move cursor
        zle -R -c               # refresh
    }

    zle -N percol_select_history
    bindkey '^R' percol_select_history
fi

Then, you can display and search your zsh histories incrementally by pressing Ctrl + r key.

tmux

Here are some examples of tmux and percol integration.

bind b split-window "tmux lsw | percol --initial-index $(tmux lsw | awk '/active.$/ {print NR-1}') | cut -d':' -f 1 | tr -d '\n' | xargs -0 tmux select-window -t"
bind B split-window "tmux ls | percol --initial-index $(tmux ls | awk \"/^$(tmux display-message -p '#{session_name}'):/ {print NR-1}\") | cut -d':' -f 1 | tr -d '\n' | xargs -0 tmux switch-client -t"

By putting above 2 settings into tmux.conf, you can select a tmux window with ${TMUX_PREFIX} b keys and session with ${TMUX_PREFIX} B keys.

Attaching to running tmux sessions can also be made easier with percol with this function(tested to work in bash and zsh)

function pattach() {
    if [[ $1 == "" ]]; then
        PERCOL=percol
    else
        PERCOL="percol --query $1"
    fi

    sessions=$(tmux ls)
    [ $? -ne 0 ] && return

    session=$(echo $sessions | eval $PERCOL | cut -d : -f 1)
    if [[ -n "$session" ]]; then
        tmux att -t $session
    fi
}

Calling percol from Python

Even though Percol is mainly designed as a UNIX command line tool, you can call it from your Python code like so:

from cStringIO import StringIO
from percol import Percol
from percol.actions import no_output

def main(candidates):
    si, so, se = StringIO(), StringIO(), StringIO()
    with Percol(
            actions=[no_output],
            descriptors={'stdin': si, 'stdout': so, 'stderr': se},
            candidates=iter(candidates)) as p:
        p.loop()
    results = p.model_candidate.get_selected_results_with_index()
    return [r[0] for r in results]

if __name__ == "__main__":
    candidates = ['foo', 'bar', 'baz']
    results = main(candidates)
    print("You picked: {!r}".format(results))

Configuration

Configuration file for percol should be placed under ${HOME}/.percol.d/ and named rc.py.

Here is an example ~/.percol.d/rc.py.

# X / _ / X
percol.view.PROMPT  = ur"<bold><yellow>X / _ / X</yellow></bold> %q"

# Emacs like
percol.import_keymap({
    "C-h" : lambda percol: percol.command.delete_backward_char(),
    "C-d" : lambda percol: percol.command.delete_forward_char(),
    "C-k" : lambda percol: percol.command.kill_end_of_line(),
    "C-y" : lambda percol: percol.command.yank(),
    "C-t" : lambda percol: percol.command.transpose_chars(),
    "C-a" : lambda percol: percol.command.beginning_of_line(),
    "C-e" : lambda percol: percol.command.end_of_line(),
    "C-b" : lambda percol: percol.command.backward_char(),
    "C-f" : lambda percol: percol.command.forward_char(),
    "M-f" : lambda percol: percol.command.forward_word(),
    "M-b" : lambda percol: percol.command.backward_word(),
    "M-d" : lambda percol: percol.command.delete_forward_word(),
    "M-h" : lambda percol: percol.command.delete_backward_word(),
    "C-n" : lambda percol: percol.command.select_next(),
    "C-p" : lambda percol: percol.command.select_previous(),
    "C-v" : lambda percol: percol.command.select_next_page(),
    "M-v" : lambda percol: percol.command.select_previous_page(),
    "M-<" : lambda percol: percol.command.select_top(),
    "M->" : lambda percol: percol.command.select_bottom(),
    "C-m" : lambda percol: percol.finish(),
    "C-j" : lambda percol: percol.finish(),
    "C-g" : lambda percol: percol.cancel(),
})

Customizing prompt

In percol, a prompt consists of two part: PROMPT and RPROMPT, like zsh. As the following example shows, each part appearance can be customized by specifying a prompt format into percol.view.PROMPT and percol.view.RPROMPT respectively.

percol.view.PROMPT = ur"<blue>Input:</blue> %q"
percol.view.RPROMPT = ur"(%F) [%i/%I]"

In prompt formats, a character preceded by % indicates a prompt format specifier and is expanded into a corresponding system value.

  • %%
    • Display % itself
  • %q
    • Display query and caret
  • %Q
    • Display query without caret
  • %n
    • Page number
  • %N
    • Total page number
  • %i
    • Current line number
  • %I
    • Total line number
  • %c
    • Caret position
  • %k
    • Last input key

Dynamic prompt

By changing percol.view.PROMPT into a getter, percol prompts becomes more fancy.

# Change prompt in response to the status of case sensitivity
percol.view.__class__.PROMPT = property(
    lambda self:
    ur"<bold><blue>QUERY </blue>[a]:</bold> %q" if percol.model.finder.case_insensitive
    else ur"<bold><green>QUERY </green>[A]:</bold> %q"
)

Custom format specifiers

# Display finder name in RPROMPT
percol.view.prompt_replacees["F"] = lambda self, **args: self.model.finder.get_name()
percol.view.RPROMPT = ur"(%F) [%i/%I]"

Customizing styles

For now, styles of following 4 items can be customized in rc.py.

percol.view.CANDIDATES_LINE_BASIC    = ("on_default", "default")
percol.view.CANDIDATES_LINE_SELECTED = ("underline", "on_yellow", "white")
percol.view.CANDIDATES_LINE_MARKED   = ("bold", "on_cyan", "black")
percol.view.CANDIDATES_LINE_QUERY    = ("yellow", "bold")

Each RHS is a tuple of style specifiers listed below.

Foreground Colors

  • "black" for curses.COLOR_BLACK
  • "red" for curses.COLOR_RED
  • "green" for curses.COLOR_GREEN
  • "yellow" for curses.COLOR_YELLOW
  • "blue" for curses.COLOR_BLUE
  • "magenta" for curses.COLOR_MAGENTA
  • "cyan" for curses.COLOR_CYAN
  • "white" for curses.COLOR_WHITE

Background Color

  • "on_black" for curses.COLOR_BLACK
  • "on_red" for curses.COLOR_RED
  • "on_green" for curses.COLOR_GREEN
  • "on_yellow" for curses.COLOR_YELLOW
  • "on_blue" for curses.COLOR_BLUE
  • "on_magenta" for curses.COLOR_MAGENTA
  • "on_cyan" for curses.COLOR_CYAN
  • "on_white" for curses.COLOR_WHITE

Attributes

  • "altcharset" for curses.A_ALTCHARSET
  • "blink" for curses.A_BLINK
  • "bold" for curses.A_BOLD
  • "dim" for curses.A_DIM
  • "normal" for curses.A_NORMAL
  • "standout" for curses.A_STANDOUT
  • "underline" for curses.A_UNDERLINE
  • "reverse" for curses.A_REVERSE

Matching Method

By default, percol interprets input queries by users as string. If you prefer regular expression, try --match-method command line option.

$ percol --match-method regex

Migemo support

percol supports migemo (http://0xcc.net/migemo/) matching, which allows us to search Japanese documents with ASCII characters.

$ percol --match-method migemo

To use this feature, you need to install C/Migemo (https://github.com/koron/cmigemo). In Ubuntu, it's simple:

$ sudo apt-get install cmigemo

After that, by specifying a command line argument --match-method migemo, you can use migemo in percol.

NOTE: This feature uses python-cmigemo package (https://github.com/mooz/python-cmigemo). Doing pip install percol also installs this package too.

Dictionary settings

By default, percol assumes the path of a dictionary for migemo is /usr/local/share/migemo/utf-8/migemo-dict. If the dictionary is located in a different place, you should tell the location via rc.py.

For example, if the path of the dictionary is /path/to/a/migemo-dict, put lines below into your rc.py.

from percol.finder import FinderMultiQueryMigemo
FinderMultiQueryMigemo.dictionary_path = "/path/to/a/migemo-dict"

Minimum query length

If the query length is too short, migemo generates very long regular expression. To deal with this problem, percol does not pass a query if the length of the query is shorter than 2 and treat the query as raw regular expression.

To change this behavior, change the value of FinderMultiQueryMigemo.minimum_query_length like following settings.

from percol.finder import FinderMultiQueryMigemo
FinderMultiQueryMigemo.minimum_query_length = 1

Pinyin support

Now percol supports pinyin (http://en.wikipedia.org/wiki/Pinyin) for matching Chinese characters.

$ percol --match-method pinyin

In this matching method, first char of each Chinese character's pinyin sequence is used for matching. For example, 'zw' matches '中文' (ZhongWen), '中午'(ZhongWu), '作为' (ZuoWei) etc.

Extra package pinin(https://pypi.python.org/pypi/pinyin/0.2.5) needed.

Switching matching method dynamically

Matching method can be switched dynamically (at run time) by executing percol.command.specify_finder(FinderClass) or percol.command.toggle_finder(FinderClass). In addition, percol.command.specify_case_sensitive(case_sensitive) and percol.command.toggle_case_sensitive() change the matching status of case sensitivity.

from percol.finder import FinderMultiQueryMigemo, FinderMultiQueryRegex
percol.import_keymap({
    "M-c" : lambda percol: percol.command.toggle_case_sensitive(),
    "M-m" : lambda percol: percol.command.toggle_finder(FinderMultiQueryMigemo),
    "M-r" : lambda percol: percol.command.toggle_finder(FinderMultiQueryRegex)
})

Tips

Selecting multiple candidates

You can select and let percol to output multiple candidates by percol.command.toggle_mark_and_next() (which is bound to C-SPC by default).

percol.command.mark_all(), percol.command.unmark_all() and percol.command.toggle_mark_all() are useful to mark / unmark all candidates at once.

Z Shell support

A zsh completing-function for percol is available in https://github.com/mooz/percol/blob/master/tools/zsh/_percol .

percol's People

Contributors

anarcat avatar anekos avatar askervin avatar bamanzi avatar bawaaaaah avatar chickenprop avatar dtreiter avatar dweinstein avatar hirochachacha avatar jailuthra avatar jeffchien avatar kaorimatz avatar kozo2 avatar kraymer avatar kunev avatar livibetter avatar lost-theory avatar lurdan avatar mooz avatar msabramo avatar quiver avatar raine avatar saitoha avatar sankitch avatar syohex avatar tkf avatar troter avatar viraptor avatar xuchunyang avatar yanma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

percol's Issues

AttributeError: 'SelectorModel' object has no attribute 'killed'

➜ ps aux | percol
Traceback (most recent call last):
  File "/usr/local/bin/percol", line 31, in <module>
    main()
  File "/usr/local/lib/python2.7/site-packages/percol/cli.py", line 284, in main
    exit_code = percol.loop()
  File "/usr/local/lib/python2.7/site-packages/percol/__init__.py", line 180, in loop
    self.handle_key(self.screen.getch())
  File "/usr/local/lib/python2.7/site-packages/percol/__init__.py", line 248, in handle_key
    self.last_key = self.handle_normal_key(ch)
  File "/usr/local/lib/python2.7/site-packages/percol/__init__.py", line 264, in handle_normal_key
    self.keymap[k](self)
  File "~/.percol.d/rc.py", line 7, in <lambda>
    "C-y" : lambda percol: percol.command.yank(),
  File "/usr/local/lib/python2.7/site-packages/percol/command.py", line 219, in yank
    if self.model.killed:
AttributeError: 'SelectorModel' object has no attribute 'killed'
  • OS X 10.9 & Python 2.7.7
  • Ubuntu 12.04 & Python 2.6.3
  • Percol 0.1.0

Configurable `~/percol.d/` location

Please allow ~/percol.d/ to be configurable through an environment variable, and even better - add support for XDG specification, i.e. ~/.config/percol.d/

Awesome tool. thanks!

Error when rc.py have encoding line.

My editor add encoding lines at the top off my .py files and it make percol don't read it's. The problem can be solved by replacing some lines in load_rc function, please change this:

with open(path, 'r') as rc:
     exec(rc.read().decode(encoding), locals())

for it:

execfile(path, locals())

and my problem will be fixed.

encoding error

Hi,

I get this since a few days. I'm using percol with zsh for history

Error: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)

Maybe I mistyped a command, but I don't kno how to get rid of it.
Thanks

Is the number of input lines configurable?

When the bash history is piped to percol with the command:

bind -x '"\C-R": READLINE_LINE=$(history | tac | cut -c 8- | percol --query "${READLINE_LINE}") READLINE_POINT='

percol searches only in the first "SOME_NUMBER" of lines (1000?). Is this number configurable somewhere?

Thanks.

Feature request: negate matches

I would like Percol to be able to work in a "reverse" or "negate" mode, in which lines matching my query strings would be removed from the output. It would be the equivalent of grep -v, but with Percol's awesomeness. :)

Results being reordered strangely

I am having a problem with Percol not sorting its results consistently. Under a certain condition, it reverses the input. I will try to illustrate:

function onlydirs {
    while read dir
    do
        [[ -d $dir ]] && echo "$dir"
    done
}
function p {
    percol --prompt-bottom --result-bottom-up
}

locate -eiA /usr/src/linux-headers-3.1 ext3 | onlydirs | xargs -d '\n' ls -dt | p

When I run that, Percol displays:

/usr/src/linux-headers-3.13.0-45/fs/ext3
/usr/src/linux-headers-3.16.0-30/fs/ext3

See how 3.13 is listed first.

But if I run:

locate -eiA /usr/src/linux-headers-3.1 | onlydirs | xargs -d '\n' ls -dt | p

Then after typing ext3 into Percol, it displays:

/usr/src/linux-headers-3.16.0-30/fs/ext3
/usr/src/linux-headers-3.13.0-45/fs/ext3

See how the lines have been reversed.

I cannot figure out why this is happening. If I take the second example and pipe it through grep ext3 instead of Percol (which should have the same effect as typing ext3 into Percol after it comes up), the order is correct, with 3.13 being before 3.16.

For some reason, Percol is reordering these lines depending on other, non-matching lines of input.

Thanks.

Incorrect fsf address

Hello.

I've package percol for Fedora and discower you have outdated file headers:

percol.x86_64: E: incorrect-fsf-address /usr/bin/percol
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/command.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/debug.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/view.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/tty.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/ansi.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/markup.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/display.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/action.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/lazyarray.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/__init__.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/info.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/model.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/actions.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/cli.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/key.py
percol.x86_64: E: incorrect-fsf-address /usr/lib/python3.4/site-packages/percol/finder.py

By our guidelines https://fedoraproject.org/wiki/Common_Rpmlint_issues#incorrect-fsf-address I shoul inform you.

Error run on python3 0.1.0 release

It marked support python3, but apperently is not:

$ percol
Traceback (most recent call last):
  File "/bin/percol", line 31, in <module>
    main()
  File "/usr/lib/python3.4/site-packages/percol/cli.py", line 225, in main
    tty_f.write(INSTRUCTION_TEXT)
TypeError: 'str' does not support the buffer interface

Is it somewere I wrong?

Spaces in search query

Is it somehow possible to have search queries contain spaces, because whenever I have a space in a query, it seems to interpret it as two separate queries.

For example (in regex mode): [0-9]{2} USER (i.e. a space, two numbers, a space and then the string USER) should match

CHAPTER 26 USER: 180
CHAPTER 26 USER: 2

But also matches:

BOOK 6 USER: 787
BOOK 6 USER: 89
LOCATION 111 USER: 709
LOCATION 120 USER: 2

Is there anyway to tell Percol to interpret the spaces as part of the search query?

--auto-match drops 2nd item in list

Hello,

I found an interesting bug when using the --auto-match flag. I can reproduce it with 0.1.0 installed from pypi on linux and osx. I am using python 2.7.

First, the correct behavior, without --auto-match:

$ echo -e "1\n2\n3\n4\n5" | percol
QUERY>                                                                                                     (1/5) [1/1]
1
2
3
4
5

Next, the buggy behavior with --auto-match, the 2nd list item is dropped:

$ echo -e "1\n2\n3\n4\n5" | percol --auto-match
QUERY>                                                                                                     (1/4) [1/1]
1
3
4
5

Interesting, huh? 😸

If I check out the original commit where this feature was added, 00b5417, then I get the correct behavior. If I check out the commit where this feature was refactored, bd59b87, then I get the buggy behavior. So perhaps that refactoring is now doing something unsafe (consuming the 2nd element somehow).

If the matching line is too long, percale will only display first part of the line

Hi, Is it possible to display multiple lines if the matching line is too long?
I had a long command which will be multiple lines in the terminal:

A LONG LONG LONG...Line A
A LONG LONG LONG...Line B

When I search by Long (say, ctrl^R for the command), currently it is only displaying partial of the command (not in multiple lines), so I can not tell the difference of both lines.

Thanks!

New README example

From HN:

The gif animation is confusing to me because the shell appears to be extensively customized, so I can't tell what is percol and what is crazy zshell customization.

I'd have to agree with this - the auto-fu plugin makes it a little unclear (as it's doing a lot of things as well) which parts of the GIF are actually from percol. Would love to see an updated version that just uses a plain prompt.

how to pass an array to percol?

If a have an array
arr = [a, b, c]
and i want to pass this array to percol, how could i do it?

Thanks for your answer! Great software piece!

percol is not helpful when the stream contains font formatting

I was trying to use percol in almost everything.
I had aliased my ls to '\ls -pF --color=always' and when I do ls | percol, the color formatting translates to their color codes in percol. Is there a way to mask that in percol? Or actually show those colors in percol?

For now I remove the --color=always flag from ls when piping the output to percol.

Another instance where I faced this was when I wanted to quickly grep for something in man. So I did "man tmux | percol" but percol is not useful there as it doesn't work with the formatting chars used in man.

Are you planning to add support for that?

Thanks.

Long query in prompt

Long query is truncated in percol. If (1) the query is shifted to left to make the caret visible or (2) break the line, it would be great. I think "break the line" is better because you can see all query you are typing.

percol functions only from root

Setup completes without error, but when run from an account other than root I get this error:

$ ls | percol
Traceback (most recent call last):
  File "/usr/local/bin/percol", line 29, in <module>
    from percol.cli import main
ImportError: No module named percol.cli

I presume this has to do with my python version or configuration, but don't know how to fix it.

$ uname -a ; python --version
Linux wh-lap-090 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:12:00 UTC 2013 i686 i686 i686 GNU/Linux
Python 2.7.5+

$ git log --abbrev-commit -n 1
commit 03aaf84
Merge: 40f9887 db4d8d7
Author: mooz <[email protected]>
Date:   Sun Jun 15 00:11:03 2014 +0900

    Merge branch 'master' of github.com:mooz/percol

How to select nothing?

Is there a standard way to select nothing in percol? I've been using ctrl+c so far but it prints an error and doesn't clean up the screen.

Separate main() in cli.py

main() in cli.py is huge and not so customizable. It would be nice to separate it into smaller functions.

Python3.x install error

Hi, I really enjoy using your terminal tool.

Trying to install percol on python 3 fails:

$ python --version
Python 3.3.2

$ pip install percol

Downloading/unpacking percol
  You are installing an externally hosted file. Future versions of pip will default to disallowing externally hosted files.
  You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files.
  Downloading master
  Running setup.py egg_info for package percol
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/private/var/folders/yp/n_vh185d1z39k_xmp5wwwm1m0000gn/T/pip_build_azu/percol/setup.py", line 5, in <module>
        import percol
      File "./percol/__init__.py", line 40, in <module>
        import debug, action
    ImportError: No module named 'debug'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/private/var/folders/yp/n_vh185d1z39k_xmp5wwwm1m0000gn/T/pip_build_azu/percol/setup.py", line 5, in <module>

    import percol

  File "./percol/__init__.py", line 40, in <module>

    import debug, action

ImportError: No module named 'debug'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /private/var/folders/yp/n_vh185d1z39k_xmp5wwwm1m0000gn/T/pip_build_azu/percol
Storing complete log in /Users/azu/.pip/pip.log

Python API and documentation

Hi, thanks for the nice Python app.

It will be nice if there is a documentation to use percol as a Python module. I am requesting this because I am using percol as a Python module for my advanced shell history app called RASH. I want to use percol as Python module as I want to issue request to SQLite DB as you type query in percol.

I have several suggestions:

  • Move most of the code in bin/percol to percol.cli or something like that. Ideally, bin/percol just contains from percol.cli import main; main() (not one-linear, of course ^^). Otherwise, people need to reimplement functions such as load_rc.
  • Some arguments for percol.Percol need to be set even if it is optional. For example, I needed to pass candidates=[].
  • Pass finder instance or add a way to pass arguments for the finder class. I am passing argument by dynamically modifying class attribute. Not cool.
  • Add a way to change appearance of candidates. For example, I want to show "score" for each candidate when searching. It's something like real-to-display / display-to-real in helm/anything. How about allowing any object that have __str__ for collection (so, you need to convert it to strings somewhere)? Module user can get that object by passing some custom actions.

Here is the related part in RASH:
https://github.com/tkf/rash/blob/master/rash/interactive_search.py

Feature request: select line near search match

Using percol on a file with multi-line records, I'd like to search to find candidate records, up/down to choose, (?) to pick a line near that.

One suggestion would be un-narrowing (clearing the search query text) and scrolling down to the same line. It can probably be that simple at first, but later the right thing is probably to have bs restore the query, or something like that.

Unicode parsing crashes percol

While trying to use percol with a logfile containing utf characters I'm getting the following error:

jsegura@air:~/tmp % percol i.log                                                                 [ 7:45AM]
Traceback (most recent call last):
  File "/usr/local/bin/percol", line 31, in <module>
    main()
  File "/Library/Python/2.7/site-packages/percol/cli.py", line 238, in main
    exit_code = percol.loop()
  File "/Library/Python/2.7/site-packages/percol/__init__.py", line 180, in loop
    self.view.refresh_display()
  File "/Library/Python/2.7/site-packages/percol/view.py", line 67, in refresh_display
    self.display_results()
  File "/Library/Python/2.7/site-packages/percol/view.py", line 113, in display_results
    is_marked = self.model.get_is_marked(cand_nth))
  File "/Library/Python/2.7/site-packages/percol/view.py", line 88, in display_result
    self.display_line(y, 0, line, style = line_style)
  File "/Library/Python/2.7/site-packages/percol/view.py", line 74, in display_line
    self.display.add_aligned_string(s, y_offset = y, x_offset = x, style = style, fill = True)
  File "/Library/Python/2.7/site-packages/percol/display.py", line 256, in add_aligned_string
    self.add_string(s, pos_y, pos_x, style)
  File "/Library/Python/2.7/site-packages/percol/display.py", line 282, in add_string
    self.addnstr(pos_y, pos_x, s, n if n >= 0 else self.WIDTH - pos_x, style)
  File "/Library/Python/2.7/site-packages/percol/display.py", line 305, in addnstr
    bytes_count_to_display = screen_length_to_bytes_count(s, n, self.encoding)
  File "/Library/Python/2.7/site-packages/percol/display.py", line 104, in screen_length_to_bytes_count
    char_bytes_count = len(unicode_char.encode(encoding))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb7' in position 0: ordinal not in range(128)

File (character ·):

jsegura@air:~/tmp % cat i.log                                                                    [ 8:30AM]
[2014/06/10 13:40:17 CEST] [INFO] (cluster.func·004:1028) Recovering local server
[2014/06/10 13:40:17 CEST] [INFO] (cluster.(*ClusterConfiguration).recover:1054) No shards to recover for 1

This is too awesome

I cannot upvote this enough. Thank you for the amazing tool!!

Has anyone started a repository of helpful bash aliases using percol? I've just made a few that are really useful for me.

Here is one for Docker that lets you choose which running docker image you would like to stop:

docker stop $(docker ps | percol | awk '{print $1;}')

Inverse matching patterns (e.g. "!pattern")

fzf has !pattern matching, which excludes anything matching that pattern. It would be really great to have this in Percol. (It'd be great to have all of its pattern types, really. =)

Having trouble installing percol without sudo

Hi,

I tried the following:

python setup.py install --prefix=~/usr_local
$ export PATH=~/usr_local/bin:$PATH

After doing that I am able to execute percol from anywhere but it fails with this error:
"ImportError: No module named percol.cli"

How do I fix it?

Cascade search

I use frequently following scenario:

<pipe> | percol | pecol | <pipe>

In the first call of the percol I choose multiple output (percol.command.toggle_mark_all()), in the second call of the
percol I am searching through the output of the first one.

This works. But I have to decide to call multiple percol at beginning. What I want is to call just:

<pipe> | pecol | <pipe>

but with possibilities to cascade search. I would like to press M- to say:
"OK, what I matched now I want to search with another pattern".

Is possible to do it?

Using `percol` from `fish` shell

Trying to use percol from fish as output to other commands doesn't work.

ls | percol works as expected.

cd (ls | percol) (not a typo, fish uses (...) instead of bash/zsh's $(...)) closes without doing anything.

Japanese characters become empty.

Hello, mooz.
I'm using percol very conveniently and I thank you for providing
such a good program.

When I select a item including japanese characters, the item becomes
empty in some case.

For exmaple, If I execute following commands in a directory which has
two files, "hoge" and "ほげ", they output as below.

$ ls | percol             # I select hoge by percol
hoge
$ ls | percol             # I select ほげ by percol
ほげ
$ ls | percol | cat     # I select hoge by percol
hoge
$ ls | percol | cat     # I select ほげ by percol
(no output)

I predict that the fourth command output "ほげ" but do not.
Is it a wrong behavior?

kbkbkbkb1

how to bind escape key?

These dont seem to work

"Escape" : lambda percol: percol.cancel(),
"Esc" : lambda percol: percol.cancel(),

Allow word wrap, or horizontal scrolling?

Is there any way we could either enable some kind of wrapping mode, and/or allow horizontal scrolling?

I'm using peco to analyse logfiles with some rather long loglines - and the pertinent content is at the end of the line (i.e. off to the right of the screen).

Prompt at the bottom

I'd like to have prompt at the bottom because you need to change your focus to the top of the terminal when start using percol. It would be nice if percol can show candidates and prompt "upside down", like this:

|
|
| candidate 3
| candidate 2
| candidate 1
| QUERY>

Can percol have an option to do this?

Changing colors

Thanks for providing this great tool.

I would like to customize the colors. I'm on Ubuntu 14.04 and I've installed percol using pip. I don't know what you mean by:

For now, styles of following 4 items can be customized in rc.py.

I've looked in the /usr/local/lib/python2.7/dist-packages/percol directory and do not see a rc.py file.

If you could add more details on how to customize the colors in the README.md it would be great.

Thanks

make releases

Hi!

I'm looking at packaging this for Debian, and for that purpose it would be useful to have release numbers. Otherwise I'd just package it as 0~20140716 (for example).

Thanks

zsh history with "\n"

OS X 10.10.3 / zsh 5.0.8 (x86_64-apple-darwin14.3.0)

if i executed some commands like:

 for i in $(cat list); do
  echo $i;
done

and search through the history by Ctrl-r, the result would expand to:

for i in $(cat list); do\necho $i;\ndone

the '\n' breaks the command, any chance to fix this?

thanks.

Problem binding C-j and RET

When I rebind C-j, the binding for RET is also changed. When I bind RET, neither binding is changed.

REPRODUCE CASE 1:
Put this in ~/.percol.d/rc.py:

percol.import_keymap({
    "C-j" : lambda percol: percol.command.select_next(),
})

While using percol, press RET

Expected result: selected entry is printed to stdout (default RET binding)
Actual result: the next entry becomes selected

REPRODUCE CASE 2:
Put this in ~/.percol.d/rc.py:

percol.import_keymap({
    "RET" : lambda percol: percol.command.select_next(),
})

While using percol, press RET

Expected result: the next entry becomes selected
Actual result: selected entry is printed to stdout (default C-j binding)

partial line matchers

Hi,

I would like to request the part which is left to awk in the examples as a percol feature. The way I imagine it is a "part of line" selector, which can be cycled (or selected with M-1, M-2 etc, or something like that) over configurable values like 'entire line', 'first word', 'second word', or custom regular expressions.

one use case would be ps faux | percol --partial '$2', which is not perfectly unix-y but feels natural to me. what's more important though is that I would like to be able to do ps faux | percol without prior knowledge about how exactly the output looks, find out interactively that it's the second word, hit my 'next partial matcher' binding two times, select the line and proceed.

thanks for your work on percol so far!

Escaped color codes incorrectly displayed

Here is what looks like using percol:

ls -1 | percol

X / _ / X (1/5) [1/1]
?[0m?[01;34manalysis.git?[0m
?[01;34mLinkageAnalysis.git?[0m
?[01;34mmutagenetix.git?[0m
?[01;34mmutagenetix.scripts.git?[0m
?[m

Can percol strip out these escaped color codes or render them correctly?

GBK Codec Error.

Hi Mooz,

Thank you for providing this amazing tool! It is awesome! However, when I use it in the Cygwin it will show 'gbk' codec error sometimes (perhaps there is some Chinese Character). Is there anyway to solve it?

Thank you very much!

Request: Customizable colors

I like that Percol colorizes text and the selected line background, but the white-on-magenta of the selected line is not very readable on my screen, because the contrast between the text and the magenta background is not very strong. After some digging I found where I can change the colors in view.py, but maintaining my own fork for this seems like overkill.

It'd be really nice if Percol supported customizable colors, perhaps by command-line options, or by a config file.

Thanks a lot for Percol!

How to/Feature request? How does percol handle the special case of 1 final result

Let me elaborate.

I wrote an alias in tcsh to cd to any of the subdirectories directly.

alias pcd 'set search_pattern="*\!***"; \\
                find . -type d -name "$search_pattern" | percol | \\
                xclip -i; cd xclip -o'

Let say I have directories:
abcd/pqr1/ and
abcd/pqr2/

If I do "pcd pqr (return)", it shows the above 2 directories, I select one, hit Enter and I end up in that directory. I love that! :)

But if I do "pcd pqr2 (return)", it shows the only "abcd/pqr2" directory. That correct; the filtered result has just one option. Then I hit Enter and end up in that directory.

My request: Does or can percol have a feature in the future where it automatically selects the option if and only if 1 option is available? With that feature, I can do "pcd pqr2 (return)" and boom!, I will be in abcd/pqr2; I skip the step where I am in percol and have to hit another Enter.

This feature will be useful for many other aliases of mine.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.