mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-09-21 02:17:11 +00:00
plugins: Add "gcloud" plugin (#386)
Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
This commit is contained in:
parent
f6597af711
commit
496ba61749
25
plugins/gcloud/README.md
Normal file
25
plugins/gcloud/README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# gcloud
|
||||
|
||||
This plugin provides completion support for the
|
||||
[Google Cloud SDK CLI](https://cloud.google.com/sdk/gcloud/).
|
||||
Based on [gcloud plugin for oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/gcloud).
|
||||
|
||||
To use it, add `gcloud` to the plugins array in your bashrc file.
|
||||
|
||||
```bash
|
||||
plugins=(... gcloud)
|
||||
```
|
||||
|
||||
It relies on you having installed the SDK using one of the supported options
|
||||
listed [here](https://cloud.google.com/sdk/install).
|
||||
|
||||
## Plugin Options
|
||||
|
||||
* Set `OMB_PLUGIN_GCLOUD_HOME` in your `bashrc` file before you load oh-my-bash if you have
|
||||
your GCloud SDK installed in a non-standard location. The plugin will use this
|
||||
as the base for your SDK if it finds it set already.
|
||||
|
||||
* If you do not have a `python2` in your `PATH` you'll also need to set the
|
||||
`CLOUDSDK_PYTHON` environment variable at the end of your `.bashrc`. This is
|
||||
used by the SDK to call a compatible interpreter when you run one of the
|
||||
SDK commands.
|
56
plugins/gcloud/gcloud.plugin.sh
Normal file
56
plugins/gcloud/gcloud.plugin.sh
Normal file
@ -0,0 +1,56 @@
|
||||
#!/bin/bash oh-my-bash.module
|
||||
# gcloud.plugin.sh
|
||||
# Author: Ian Chesal (github.com/ianchesal) -- ohmyzsh/gloud.plugin.zsh
|
||||
# Author: Antonino Cangialosi (github.com/ninoCan)
|
||||
# Fork of oh-my-zsh gcloud plugin
|
||||
|
||||
function _omb_plugin_gcloud_set_home_var() {
|
||||
if [[ ! ${OMB_PLUGIN_GCLOUD_HOME-} ]]; then
|
||||
local -a search_locations=(
|
||||
"$HOME/google-cloud-sdk"
|
||||
"/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
|
||||
"/opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk"
|
||||
"/usr/share/google-cloud-sdk"
|
||||
"/snap/google-cloud-sdk/current"
|
||||
"/usr/lib/google-cloud-sdk"
|
||||
"/usr/lib64/google-cloud-sdk"
|
||||
"/opt/google-cloud-sdk"
|
||||
"/opt/local/libexec/google-cloud-sdk"
|
||||
)
|
||||
|
||||
local gcloud_sdk_location
|
||||
for gcloud_sdk_location in "${search_locations[@]}"; do
|
||||
if [[ -d $gcloud_sdk_location ]]; then
|
||||
OMB_PLUGIN_GCLOUD_HOME=$gcloud_sdk_location
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
function _omb_plugin_gcloud_set_completions() {
|
||||
if [[ ${OMB_PLUGIN_GCLOUD_HOME-} ]]; then
|
||||
# Only source this if gcloud isn't already on the path
|
||||
if _omb_util_binary_exists gcloud; then
|
||||
if [[ -f $OMB_PLUGIN_GCLOUD_HOME/path.bash.inc ]]; then
|
||||
source "$OMB_PLUGIN_GCLOUD_HOME/path.bash.inc"
|
||||
fi
|
||||
|
||||
# Look for completion file in different paths
|
||||
local -a completion_filepath_candidates=(
|
||||
"${OMB_PLUGIN_GCLOUD_HOME}/completion.bash.inc" # default location
|
||||
"/usr/share/google-cloud-sdk/completion.bash.inc" # apt-based location
|
||||
)
|
||||
local comp_file
|
||||
for comp_file in "${completion_filepath_candidates[@]}"; do
|
||||
if [[ -f $comp_file ]]; then
|
||||
source "$comp_file"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
_omb_plugin_gcloud_set_home_var
|
||||
_omb_plugin_gcloud_set_completions
|
Loading…
Reference in New Issue
Block a user