Guest User

fzf search for fullhistory

a guest
Jan 21st, 2024
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | Source Code | 0 0
  1. ############################################################################
  2. #### ZSH zshrc.d/fzf.sh
  3.  
  4. fzf-fullhistory-widget() {
  5. # If fzf was not available at configure time, check now
  6. if ! command -v fzf; then
  7. zle history-incremental-search-backward
  8. return
  9. fi
  10. local reverser=tac
  11. if ! command -v tac >/dev/null 2>&1; then
  12. reverser=(tail -r)
  13. fi
  14. zle -U "$($reverser ~/.fullhistory \
  15. | fzf --with-nth 3.. -n 2.. --tiebreak=index --preview 'echo {} | cut -d" " -f 4-' --preview-window=up,3,wrap --bind change:top \
  16. | cut -d" " -f 4- \
  17. | sed $'s/[ \t]*$//')"
  18. # Needed if we don't use fzf fullscreen
  19. zle reset-prompt
  20. }
  21. zle -N fzf-fullhistory-widget
  22. bindkey '^R' fzf-fullhistory-widget
  23.  
  24. ############################################################################
  25. #### bash bashrc.d/fzf.sh
  26. if ! command -v fzf >/dev/null 2>&1; then
  27. return
  28. fi
  29.  
  30. # Detect line editing available, and only use bind if it can work
  31. if [[ "$(set -o | grep 'emacs\|\bvi\b' | cut -f2 | tr '\n' ':')" != 'off:off:' ]]; then
  32. bind '"\C-r": "\C-x1\e^\er"'
  33. bind -x '"\C-x1": __fzf_history';
  34. fi
  35.  
  36.  
  37. __fzf_history ()
  38. {
  39. local reverser=tac
  40. if ! command -v tac >/dev/null 2>&1; then
  41. reverser='tail -r'
  42. fi
  43. __ehc "$($reverser ~/.fullhistory \
  44. | fzf --with-nth 3.. -n 2.. --tiebreak=index --preview 'echo {} | cut -d" " -f 4-' --preview-window=up,3,wrap --bind change:top \
  45. | cut -d" " -f 4- \
  46. | sed $'s/[ \t]*$//')"
  47. }
  48.  
  49. __ehc()
  50. {
  51. if
  52. [[ -n $1 ]]
  53. then
  54. bind '"\er": redraw-current-line'
  55. bind '"\e^": magic-space'
  56. READLINE_LINE=${READLINE_LINE:+${READLINE_LINE:0:READLINE_POINT}}${1}${READLINE_LINE:+${READLINE_LINE:READLINE_POINT}}
  57. READLINE_POINT=$(( READLINE_POINT + ${#1} ))
  58. else
  59. bind '"\er":'
  60. bind '"\e^":'
  61. fi
  62. }
Advertisement
Add Comment
Please, Sign In to add comment