Add gcloud plugin (#8144)
* A gcloud plugin
This PR addresses issue #6205
This adds support for loading completion for the Google Cloud SDK
command line tools. It searches the known paths for an SDK and loads the
provided completion if it is found. Users can supply a custom location
for the SDK by setting `CLOUDSDK_HOME` in their `zshrc` before loading
oh-my-zsh plugins.
* Canoncial zsh and some safe guards
Based on a PR review from mcornella. All off this has now been tested
on the following variants:
- macOS 10.14.6 - Homebrew
- macOS 10.14.6 - Custom install
- Ubuntu 16.04.6 LTS - apt install
- Ubuntu 18.04.3 LTS - apt install
- Ubuntu 18.04.3 LTS - snap classic install
- CentOS 7 - yum install
Diff
1diff --git a/plugins/gcloud/README.md b/plugins/gcloud/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..e7ce0e0f19ffff863a78130ec51b72a6506ebf2a
4--- /dev/null
5+++ b/plugins/gcloud/README.md
6@@ -0,0 +1,24 @@
7+# gcloud
8+
9+This plugin provides completion support for the
10+[Google Cloud SDK CLI](https://cloud.google.com/sdk/gcloud/).
11+
12+To use it, add `gcloud` to the plugins array in your zshrc file.
13+
14+```zsh
15+plugins=(... gcloud)
16+```
17+
18+It relies on you having installed the SDK using one of the supported options
19+listed [here](https://cloud.google.com/sdk/install).
20+
21+## Plugin Options
22+
23+* Set `CLOUDSDK_HOME` in your `zshrc` file before you load oh-my-zsh if you have
24+your GCloud SDK installed in a non-standard location. The plugin will use this
25+as the base for your SDK if it finds it set already.
26+
27+* If you do not have a `python2` in your `PATH` you'll also need to set the
28+`CLOUDSDK_PYTHON` environment variable at the end of your `.zshrc`. This is
29+used by the SDK to call a compatible interpreter when you run one of the
30+SDK commands.
31diff --git a/plugins/gcloud/gcloud.plugin.zsh b/plugins/gcloud/gcloud.plugin.zsh
32new file mode 100644
33index 0000000000000000000000000000000000000000..6433a72522a5a0c227104c24879b74477b1f0b5b
34--- /dev/null
35+++ b/plugins/gcloud/gcloud.plugin.zsh
36@@ -0,0 +1,32 @@
37+#####################################################
38+# gcloud plugin for oh-my-zsh #
39+# Author: Ian Chesal (github.com/ianchesal) #
40+#####################################################
41+
42+if [[ -z "${CLOUDSDK_HOME}" ]]; then
43+ search_locations=(
44+ "$HOME/google-cloud-sdk"
45+ "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
46+ "/usr/share/google-cloud-sdk"
47+ "/snap/google-cloud-sdk/current"
48+ "/usr/lib64/google-cloud-sdk/"
49+ )
50+
51+ for gcloud_sdk_location in $search_locations; do
52+ if [[ -d "${gcloud_sdk_location}" ]]; then
53+ CLOUDSDK_HOME="${gcloud_sdk_location}"
54+ break
55+ fi
56+ done
57+fi
58+
59+if (( ${+CLOUDSDK_HOME} )); then
60+ if (( ! $+commands[gcloud] )); then
61+ # Only source this if GCloud isn't already on the path
62+ if [[ -f "${CLOUDSDK_HOME}/path.zsh.inc" ]]; then
63+ source "${CLOUDSDK_HOME}/path.zsh.inc"
64+ fi
65+ fi
66+ source "${CLOUDSDK_HOME}/completion.zsh.inc"
67+ export CLOUDSDK_HOME
68+fi