2
0

gcloud.plugin.zsh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. "/opt/homebrew/share/google-cloud-sdk"
  12. "/usr/share/google-cloud-sdk"
  13. "/snap/google-cloud-sdk/current"
  14. "/snap/google-cloud-cli/current"
  15. "/usr/lib/google-cloud-sdk"
  16. "/usr/lib64/google-cloud-sdk"
  17. "/opt/google-cloud-sdk"
  18. "/opt/google-cloud-cli"
  19. "/opt/local/libexec/google-cloud-sdk"
  20. "$HOME/.asdf/installs/gcloud/*/"
  21. )
  22. for gcloud_sdk_location in $search_locations; do
  23. if [[ -d "${gcloud_sdk_location}" ]]; then
  24. CLOUDSDK_HOME="${gcloud_sdk_location}"
  25. break
  26. fi
  27. done
  28. unset search_locations gcloud_sdk_location
  29. fi
  30. if (( ${+CLOUDSDK_HOME} )); then
  31. # Source path file
  32. if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then
  33. source "${CLOUDSDK_HOME}/path.zsh.inc"
  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