n-env 890 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copy this file into /usr/share/zsh/site-functions/
  2. # and add 'autoload n-env` to .zshrc
  3. #
  4. # This function allows to choose an environment variable
  5. # for edition with vared
  6. #
  7. # Uses n-list
  8. emulate -L zsh
  9. setopt extendedglob
  10. unsetopt equals
  11. zmodload zsh/curses
  12. local IFS="
  13. "
  14. [ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
  15. [ -f ~/.config/znt/n-env.conf ] && builtin source ~/.config/znt/n-env.conf
  16. local list
  17. local selected
  18. NLIST_REMEMBER_STATE=0
  19. list=( `env` )
  20. list=( "${(@M)list:#(#i)*$1*}" )
  21. local NLIST_GREP_STRING="$1"
  22. if [ "$#list" -eq 0 ]; then
  23. echo "No matching variables"
  24. return 1
  25. fi
  26. list=( "${(@i)list}" )
  27. n-list "$list[@]"
  28. if [ "$REPLY" -gt 0 ]; then
  29. selected="$reply[REPLY]"
  30. selected="${selected%%=*}"
  31. echo "Editing \`$selected':"
  32. print -rs "vared \"$selected\""
  33. vared "$selected"
  34. fi
  35. # vim: set filetype=zsh: