n-history 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copy this file into /usr/share/zsh/site-functions/
  2. # and add 'autoload n-history` to .zshrc
  3. #
  4. # This function allows to browse Z shell's history and use the
  5. # entries
  6. #
  7. # Uses n-list
  8. emulate -L zsh
  9. setopt extendedglob
  10. zmodload zsh/curses
  11. local IFS="
  12. "
  13. unset NLIST_COLORING_PATTERN
  14. [ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf
  15. [ -f ~/.config/znt/n-history.conf ] && . ~/.config/znt/n-history.conf
  16. local list
  17. local selected
  18. NLIST_REMEMBER_STATE=0
  19. list=( `builtin history -rn 1` )
  20. list=( "${(@M)list:#(#i)*$1*}" )
  21. local NLIST_GREP_STRING="$1"
  22. if [ "$#list" -eq 0 ]; then
  23. echo "No matching history entries"
  24. return 1
  25. fi
  26. n-list "${list[@]}"
  27. if [ "$REPLY" -gt 0 ]; then
  28. selected="$reply[REPLY]"
  29. # ZLE?
  30. if [ "${(t)CURSOR}" = "integer-local-special" ]; then
  31. zle redisplay
  32. zle kill-whole-line
  33. zle -U "$selected"
  34. else
  35. print -zr "$selected"
  36. fi
  37. else
  38. [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay
  39. fi
  40. # vim: set filetype=zsh: