compfix.zsh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Handle completions insecurities (i.e., completion-dependent directories with
  2. # insecure ownership or permissions) by:
  3. #
  4. # * Human-readably notifying the user of these insecurities.
  5. function handle_completion_insecurities() {
  6. # List of the absolute paths of all unique insecure directories, split on
  7. # newline from compaudit()'s output resembling:
  8. #
  9. # There are insecure directories:
  10. # /usr/share/zsh/site-functions
  11. # /usr/share/zsh/5.0.6/functions
  12. # /usr/share/zsh
  13. # /usr/share/zsh/5.0.6
  14. #
  15. # Since the ignorable first line is printed to stderr and thus not captured,
  16. # stderr is squelched to prevent this output from leaking to the user.
  17. local -aU insecure_dirs
  18. insecure_dirs=( ${(f@):-"$(compaudit 2>/dev/null)"} )
  19. # If no such directories exist, get us out of here.
  20. [[ -z "${insecure_dirs}" ]] && return
  21. # List ownership and permissions of all insecure directories.
  22. print "[oh-my-zsh] Insecure completion-dependent directories detected:"
  23. ls -ld "${(@)insecure_dirs}"
  24. cat <<EOD
  25. [oh-my-zsh] For safety, we will not load completions from these directories until
  26. [oh-my-zsh] you fix their permissions and ownership and restart zsh.
  27. [oh-my-zsh] See the above list for directories with group or other writability.
  28. [oh-my-zsh] To fix your permissions you can do so by disabling
  29. [oh-my-zsh] the write permission of "group" and "others" and making sure that the
  30. [oh-my-zsh] owner of these directories is either root or your current user.
  31. [oh-my-zsh] The following command may help:
  32. [oh-my-zsh] compaudit | xargs chmod g-w,o-w
  33. [oh-my-zsh] If the above didn't help or you want to skip the verification of
  34. [oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
  35. [oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file.
  36. EOD
  37. }