From 5efcfc39735c818a9778172356f82ec0eb3e5916 Mon Sep 17 00:00:00 2001 From: "Jose C. Massón" <939888+Abuelodelanada@users.noreply.github.com> Date: Thu, 23 Mar 2023 05:42:20 -0300 Subject: feat(juju): add functions to get current controller and model (#11572) --- plugins/juju/juju.plugin.zsh | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'plugins/juju/juju.plugin.zsh') diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh index be8a2c7ae..0c60e35ce 100644 --- a/plugins/juju/juju.plugin.zsh +++ b/plugins/juju/juju.plugin.zsh @@ -163,10 +163,40 @@ jreld() { juju run "relation-get -r $relid - $2" --unit $2/$3 } +# Return Juju current controller +jcontroller() { + local controller="$(awk '/current-controller/ {print $2}' ~/.local/share/juju/controllers.yaml)" + if [[ -z "$controller" ]]; then + return 1 + fi + + echo $controller + return 0 +} + +# Return Juju current model +jmodel() { + local yqbin="$(whereis yq | awk '{print $2}')" + + if [[ -z "$yqbin" ]]; then + echo "--" + return 1 + fi + + local model="$(yq e ".controllers.$(jcontroller).current-model" < ~/.local/share/juju/models.yaml | cut -d/ -f2)" + + if [[ -z "$model" ]]; then + echo "--" + return 1 + fi + + echo $model + return 0 +} + # Watch juju status, with optional interval (default: 5 sec) wjst() { local interval="${1:-5}" shift $(( $# > 0 )) watch -n "$interval" --color juju status --relations --color "$@" } - -- cgit v1.2.3-70-g09d2