gcloud.plugin.zsh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #####################################################
  2. # gcloud plugin for oh-my-zsh #
  3. # Author: Ian Chesal (github.com/ianchesal) #
  4. #####################################################
  5. if [[ -z "${CLOUDSDK_HOME}" ]]; then
  6. search_locations=(
  7. "$HOME/google-cloud-sdk"
  8. "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
  9. "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
  10. "/usr/share/google-cloud-sdk"
  11. "/snap/google-cloud-sdk/current"
  12. "/usr/lib/google-cloud-sdk"
  13. "/usr/lib64/google-cloud-sdk"
  14. "/opt/google-cloud-sdk"
  15. "/opt/local/libexec/google-cloud-sdk"
  16. )
  17. for gcloud_sdk_location in $search_locations; do
  18. if [[ -d "${gcloud_sdk_location}" ]]; then
  19. CLOUDSDK_HOME="${gcloud_sdk_location}"
  20. break
  21. fi
  22. done
  23. unset search_locations gcloud_sdk_location
  24. fi
  25. if (( ${+CLOUDSDK_HOME} )); then
  26. # Only source this if gcloud isn't already on the path
  27. if (( ! $+commands[gcloud] )); then
  28. if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then
  29. source "${CLOUDSDK_HOME}/path.zsh.inc"
  30. fi
  31. fi
  32. # Look for completion file in different paths
  33. for comp_file (
  34. "${CLOUDSDK_HOME}/completion.zsh.inc" # default location
  35. "/usr/share/google-cloud-sdk/completion.zsh.inc" # apt-based location
  36. ); do
  37. if [[ -f "${comp_file}" ]]; then
  38. source "${comp_file}"
  39. break
  40. fi
  41. done
  42. unset comp_file
  43. export CLOUDSDK_HOME
  44. fi