mooz / percol

adds flavor of interactive filtering to the traditional pipe concept of UNIX shell
3.3k stars 145 forks source link

Change finish_with_exit_code so that it can return value #89

Closed yanma closed 8 years ago

yanma commented 8 years ago

The zsh function percol_select_history is so cool!

I want to make it greater by adding branch after finish. To realize it, I changed finish_with_exit_code so that it can return the value. Using this feature, you can change the history-search behavior as below.

In your .zshrc, put the lines below.

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")
    RETURN=$?
    CURSOR=$#BUFFER
    zle -R -c
    test $RETURN -eq 0 && zle accept-line
}

In your rc.py, put the lines below.

percol.import_keymap({
    "C-j" : lambda percol: percol.finish(),
    "C-k" : lambda percol: percol.finish(value=2),
    })
mooz commented 8 years ago

Cool idea! Thanks!