n-history 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. zmodload zsh/parameter
  12. local IFS="
  13. "
  14. unset NLIST_COLORING_PATTERN
  15. [ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf
  16. [ -f ~/.config/znt/n-history.conf ] && . ~/.config/znt/n-history.conf
  17. local list
  18. local selected
  19. NLIST_REMEMBER_STATE=0
  20. list=( "$history[@]" )
  21. list=( "${(@M)list:#(#i)*$1*}" )
  22. if [ "$#list" -eq 0 ]; then
  23. echo "No matching history entries"
  24. return 1
  25. fi
  26. local NLIST_GREP_STRING="$1"
  27. local NLIST_REPLACE_NEWLINES="1"
  28. n-list "${list[@]}"
  29. if [ "$REPLY" -gt 0 ]; then
  30. selected="$reply[REPLY]"
  31. # ZLE?
  32. if [ "${(t)CURSOR}" = "integer-local-special" ]; then
  33. zle redisplay
  34. zle kill-buffer
  35. zle -U "$selected"
  36. else
  37. print -zr "$selected"
  38. fi
  39. else
  40. [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay
  41. fi
  42. # vim: set filetype=zsh: