.zshenv 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # This file can get sourced with aliases enabled. To avoid alias expansion
  2. # we quote everything that can be quoted. Some aliases will still break us
  3. # though.
  4. # Don't use [[ -v ... ]] because it doesn't work in zsh < 5.4.
  5. if [[ -n "${KITTY_ORIG_ZDOTDIR+X}" ]]; then
  6. # Normally ZDOTDIR shouldn't be exported but it was in the environment
  7. # of kitty, so we export it.
  8. 'builtin' 'export' ZDOTDIR="$KITTY_ORIG_ZDOTDIR"
  9. 'builtin' 'unset' 'KITTY_ORIG_ZDOTDIR'
  10. else
  11. 'builtin' 'unset' 'ZDOTDIR'
  12. fi
  13. # Use try-always to have the right error code.
  14. {
  15. # Zsh treats empty $ZDOTDIR as if it was "/". We do the same.
  16. #
  17. # Source the user's zshenv before sourcing kitty.zsh because the former
  18. # might set fpath and other things without which kitty.zsh won't work.
  19. #
  20. # Use typeset in case we are in a function with warn_create_global in
  21. # effect. Unlikely but better safe than sorry.
  22. 'builtin' 'typeset' _ksi_file=${ZDOTDIR-~}"/.zshenv"
  23. # Zsh ignores unreadable rc files. We do the same.
  24. # Zsh ignores rc files that are directories, and so does source.
  25. [[ ! -r "$_ksi_file" ]] || 'builtin' 'source' '--' "$_ksi_file"
  26. } always {
  27. if [[ -o 'interactive' && -n "${KITTY_SHELL_INTEGRATION-}" ]]; then
  28. 'builtin' 'autoload' '--' 'is-at-least'
  29. 'is-at-least' "5.1" || {
  30. builtin echo "ZSH ${ZSH_VERSION} is too old for kitty shell integration" > /dev/stderr
  31. return
  32. }
  33. # ${(%):-%x} is the path to the current file.
  34. # On top of it we add :A:h to get the directory.
  35. 'builtin' 'typeset' _ksi_file="${${(%):-%x}:A:h}"/kitty-integration
  36. if [[ -r "$_ksi_file" ]]; then
  37. 'builtin' 'autoload' '-Uz' '--' "$_ksi_file"
  38. "${_ksi_file:t}"
  39. 'builtin' 'unfunction' '--' "${_ksi_file:t}"
  40. fi
  41. fi
  42. 'builtin' 'unset' '_ksi_file'
  43. }