percol.plugin.zsh 723 B

12345678910111213141516171819202122
  1. if which percol &> /dev/null; then
  2. function percol_select_history() {
  3. local tac
  4. which gtac &> /dev/null && tac="gtac" || { which tac &> /dev/null && tac="tac" || { tac="tail -r" } }
  5. BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
  6. CURSOR=$#BUFFER
  7. zle -R -c
  8. }
  9. zle -N percol_select_history
  10. bindkey '^R' percol_select_history
  11. if which marks &> /dev/null; then
  12. function percol_select_marks() {
  13. BUFFER=$(marks | percol --query "$LBUFFER" | awk '{print $3}')
  14. CURSOR=$#BUFFER # move cursor
  15. zle -R -c # refresh
  16. }
  17. zle -N percol_select_marks
  18. bindkey '^B' percol_select_marks
  19. fi
  20. fi