hook 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env bash
  2. # need additional step to not redefine variables value if already set
  3. \typeset old_rvm_verbose_flag old_rvm_debug_flag >/dev/null 2>/dev/null
  4. old_rvm_verbose_flag=${rvm_verbose_flag:-0}
  5. old_rvm_debug_flag=${rvm_debug_flag:-0}
  6. # silence Zsh redefinitions
  7. \typeset rvm_verbose_flag rvm_debug_flag hooks >/dev/null 2>/dev/null
  8. true rvm_verbose_flag:${rvm_verbose_flag:=${old_rvm_verbose_flag}} \
  9. rvm_hooks_path:${rvm_hooks_path:="$rvm_path/hooks"} \
  10. rvm_debug_flag:${rvm_debug_flag:=${old_rvm_debug_flag}} rvm_hook:${rvm_hook:=}
  11. if
  12. [[ -n "$rvm_hook" ]]
  13. then
  14. hooks=()
  15. if
  16. [[ -d "$rvm_hooks_path" ]]
  17. then
  18. hooks+=( "$rvm_hooks_path" )
  19. fi
  20. if
  21. [[ "$PWD/.rvm/hooks" != "$rvm_hooks_path" && -d "$PWD/.rvm/hooks" ]]
  22. then
  23. hooks+=( "$PWD/.rvm/hooks" )
  24. fi
  25. if
  26. [[ -n "${hooks[*]}" ]]
  27. then
  28. __rvm_read_lines _hooks_list <(
  29. __rvm_find -L "${hooks[@]}" -iname "$rvm_hook*" -type f 2>/dev/null || true
  30. )
  31. for hook in "${_hooks_list[@]}"
  32. do
  33. if
  34. [[ -x "${hook}" || "${hook##*/}" == "$rvm_hook" ]]
  35. then
  36. if
  37. [[ "${hook}" == "$rvm_hooks_path/"* ]] || # trust internal hooks
  38. __rvm_check_rvmrc_trustworthiness "${hook}" # ask user to trust other files
  39. then
  40. rvm_debug "Running $hook"
  41. __rvm_conditionally_do_with_env . "${hook}" >&2
  42. fi
  43. fi
  44. done
  45. fi
  46. fi
  47. unset rvm_hook hooks _hooks_list hook