gcloud.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. )
  16. for gcloud_sdk_location in $search_locations; do
  17. if [[ -d "${gcloud_sdk_location}" ]]; then
  18. CLOUDSDK_HOME="${gcloud_sdk_location}"
  19. break
  20. fi
  21. done
  22. unset search_locations gcloud_sdk_location
  23. fi
  24. if (( ${+CLOUDSDK_HOME} )); then
  25. # Only source this if gcloud isn't already on the path
  26. if (( ! $+commands[gcloud] )); then
  27. if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then
  28. source "${CLOUDSDK_HOME}/path.zsh.inc"
  29. fi
  30. fi
  31. # Look for completion file in different paths
  32. for comp_file (
  33. "${CLOUDSDK_HOME}/completion.zsh.inc" # default location
  34. "/usr/share/google-cloud-sdk/completion.zsh.inc" # apt-based location
  35. ); do
  36. if [[ -f "${comp_file}" ]]; then
  37. source "${comp_file}"
  38. break
  39. fi
  40. done
  41. unset comp_file
  42. export CLOUDSDK_HOME
  43. fi