Skip to content

Commit 5efcfc3

Browse files
feat(juju): add functions to get current controller and model (ohmyzsh#11572)
1 parent f9f01e4 commit 5efcfc3

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

plugins/juju/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,7 @@ Naming convention:
126126
- `jaddr <app_name> [unit_num]`: display app or unit IP address.
127127
- `jreld <relation_name> <app_name> <unit_num>`: display app and unit relation data.
128128
- `jclean`: destroy all controllers
129+
- `jcontroller`: display the controller your are connected to.
130+
- `jmodel`: display the model your are connected to.
129131
- `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval
130132
(default: 5s); you may pass additional arguments to `watch`.

plugins/juju/juju.plugin.zsh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,40 @@ jreld() {
163163
juju run "relation-get -r $relid - $2" --unit $2/$3
164164
}
165165

166+
# Return Juju current controller
167+
jcontroller() {
168+
local controller="$(awk '/current-controller/ {print $2}' ~/.local/share/juju/controllers.yaml)"
169+
if [[ -z "$controller" ]]; then
170+
return 1
171+
fi
172+
173+
echo $controller
174+
return 0
175+
}
176+
177+
# Return Juju current model
178+
jmodel() {
179+
local yqbin="$(whereis yq | awk '{print $2}')"
180+
181+
if [[ -z "$yqbin" ]]; then
182+
echo "--"
183+
return 1
184+
fi
185+
186+
local model="$(yq e ".controllers.$(jcontroller).current-model" < ~/.local/share/juju/models.yaml | cut -d/ -f2)"
187+
188+
if [[ -z "$model" ]]; then
189+
echo "--"
190+
return 1
191+
fi
192+
193+
echo $model
194+
return 0
195+
}
196+
166197
# Watch juju status, with optional interval (default: 5 sec)
167198
wjst() {
168199
local interval="${1:-5}"
169200
shift $(( $# > 0 ))
170201
watch -n "$interval" --color juju status --relations --color "$@"
171202
}
172-

0 commit comments

Comments
 (0)