n-functions 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copy this file into /usr/share/zsh/site-functions/
  2. # and add 'autoload n-functions` to .zshrc
  3. #
  4. # This function allows to choose a function for edition with vared
  5. #
  6. # Uses n-list
  7. emulate -L zsh
  8. setopt extendedglob
  9. zmodload zsh/curses
  10. zmodload zsh/parameter
  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-functions.conf ] && . ~/.config/znt/n-functions.conf
  16. local list
  17. local selected
  18. NLIST_REMEMBER_STATE=0
  19. list=( "${(@k)functions}" )
  20. list=( "${(@M)list:#(#i)*$1*}" )
  21. local NLIST_GREP_STRING="$1"
  22. if [ "$#list" -eq 0 ]; then
  23. echo "No matching functions"
  24. return 1
  25. fi
  26. list=( "${(@i)list}" )
  27. n-list "$list[@]"
  28. if [ "$REPLY" -gt 0 ]; then
  29. selected="$reply[REPLY]"
  30. if [ "$feditor" = "zed" ]; then
  31. echo "Editing \`$selected' (ESC ZZ or Ctrl-x-w to finish):"
  32. autoload zed
  33. print -rs "zed -f -- \"$selected\""
  34. zed -f -- "$selected"
  35. else
  36. echo "Editing \`$selected':"
  37. print -rs "vared functions\\[$selected\\]"
  38. vared functions\[$selected\]
  39. fi
  40. fi
  41. # vim: set filetype=zsh: