gcloud.plugin.zsh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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/share/google-cloud-sdk"
  9. "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
  10. "/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
  11. "/usr/share/google-cloud-sdk"
  12. "/snap/google-cloud-sdk/current"
  13. "/snap/google-cloud-cli/current"
  14. "/usr/lib/google-cloud-sdk"
  15. "/usr/lib64/google-cloud-sdk"
  16. "/opt/google-cloud-sdk"
  17. "/opt/google-cloud-cli"
  18. "/opt/local/libexec/google-cloud-sdk"
  19. )
  20. for gcloud_sdk_location in $search_locations; do
  21. if [[ -d "${gcloud_sdk_location}" ]]; then
  22. CLOUDSDK_HOME="${gcloud_sdk_location}"
  23. break
  24. fi
  25. done
  26. unset search_locations gcloud_sdk_location
  27. fi
  28. if (( ${+CLOUDSDK_HOME} )); then
  29. # Only source this if gcloud isn't already on the path
  30. if (( ! $+commands[gcloud] )); then
  31. if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then
  32. source "${CLOUDSDK_HOME}/path.zsh.inc"
  33. fi
  34. fi
  35. # Look for completion file in different paths
  36. for comp_file (
  37. "${CLOUDSDK_HOME}/completion.zsh.inc" # default location
  38. "/usr/share/google-cloud-sdk/completion.zsh.inc" # apt-based location
  39. ); do
  40. if [[ -f "${comp_file}" ]]; then
  41. source "${comp_file}"
  42. break
  43. fi
  44. done
  45. unset comp_file
  46. export CLOUDSDK_HOME
  47. fi