added oh-my-ssh back as raw code, not as a submodule.

This commit is contained in:
Johannes Findeisen 2026-11-19 19:29:16 +01:00
commit f663947bfc
1195 changed files with 126994 additions and 0 deletions

View file

@ -0,0 +1,132 @@
# juju plugin
This plugin provides useful aliases and functions for [juju](https://juju.is/) (for TAB completion,
refer to the [official repo](https://github.com/juju/juju/blob/develop/etc/bash_completion.d/juju)).
To use this plugin, add `juju` to the plugins array in your zshrc file.
```zsh
plugins=(... juju)
```
## Aliases
Naming convention:
- `!` suffix: `--force --no-wait -y`.
- `ds` suffix: `--destroy-storage`.
- `jsh` prefix means `juju show-*`.
### General
| Alias | Command | Description |
|---------|---------------------------------------------|--------------------------------------------------------|
| `j` | `juju` | The juju command |
| `jcld` | `juju clouds` | Lists all clouds with registered credentials |
| `jclda` | `juju clouds --all` | Lists all clouds available to Juju |
| `jdl` | `juju debug-log --ms` | Display log, with millisecond resolution |
| `jdlr` | `juju debug-log --ms --replay` | Replay entire log |
| `jh` | `juju help` | Show help on a command or other topic |
| `jshsl` | `juju show-status-log` | Output past statuses for the specified entity |
| `jstj` | `juju status --format=json` | Show status in json format (more detailed) |
| `jst` | `juju status --relations --color` | Show status, including relations, in color |
| `jsts` | `juju status --relations --storage --color` | Show status, including relations and storage, in color |
### Bootstrap
| Alias | Command | Description |
|---------|-------------------------------------|-------------------------------------------------------|
| `jb` | `juju bootstrap` | Initializing a Juju cloud environment |
| `jbng` | `juju bootstrap --no-gui` | Initializing a Juju cloud environment without GUI |
| `jbl` | `juju bootstrap localhost` | Initializing an lxd cloud environment |
| `jblng` | `juju bootstrap --no-gui localhost` | Initializing an lxd cloud environment without GUI |
| `jbm` | `juju bootstrap microk8s` | Initializing a MicroK8s cloud environment |
| `jbmng` | `juju bootstrap --no-gui microk8s` | Initializing a MicroK8s cloud environment without GUI |
### Controller
| Alias | Command | Description |
|----------|---------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| `jctl` | `juju controllers` | List all controllers |
| `jctlr` | `juju controllers --refresh` | List all controllers (download latest details) |
| `jdc` | `juju destroy-controller --destroy-all-models` | Destroy a controller |
| `jdc!` | `juju destroy-controller --destroy-all-models --force --no-wait -y` | Destroy a controller |
| `jdcds` | `juju destroy-controller --destroy-all-models --destroy-storage` | Destroy a controller and associated storage |
| `jdcds!` | `juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y` | Destroy a controller and associated storage |
| `jkc` | `juju kill-controller -y -t 0` | Forcibly terminate all associated resources for a Juju controller |
| `jshc` | `juju show-controller` | Shows detailed information of a controller |
| `jsw` | `juju switch` | Select or identify the current controller and model |
### Model
| Alias | Command | Description |
|----------|-------------------------------------------------------------|-------------------------------------------------------|
| `jam` | `juju add-model` | Add a hosted model |
| `jdm` | `juju destroy-model` | Non-recoverable, complete removal of a model |
| `jdm!` | `juju destroy-model --force --no-wait -y` | Non-recoverable, complete removal of a model |
| `jdmds` | `juju destroy-model --destroy-storage` | Non-recoverable, complete removal of a model |
| `jdmds!` | `juju destroy-model --destroy-storage --force --no-wait -y` | Non-recoverable, complete removal of a model |
| `jmc` | `juju model-config` | Display or set configuration values on a model |
| `jm` | `juju models` | List models a user can access on a controller |
| `jshm` | `juju show-model` | Show information about the current or specified model |
| `jsw` | `juju switch` | Select or identify the current controller and model |
### Application / unit
| Alias | Command | Description |
|----------|---------------------------------------------------------------|---------------------------------------------------------------------------|
| `jc` | `juju config` | Get, set, or reset configuration for a deployed application |
| `jde` | `juju deploy --channel=edge` | Deploy a new application or bundle from the edge channel |
| `jd` | `juju deploy` | Deploy a new application or bundle |
| `jra` | `juju run-action` | Queue an action for execution |
| `jraw` | `juju run-action --wait` | Queue an action for execution and wait for results, with optional timeout |
| `jrm` | `juju remove-application` | Remove application |
| `jrm!` | `juju remove-application --force --no-wait` | Remove application forcefully |
| `jrmds` | `juju remove-application --destroy-storage` | Remove application and destroy attached storage |
| `jrmds!` | `juju remove-application --destroy-storage --force --no-wait` | Remove application forcefully, destroying attached storage |
| `jrp` | `juju refresh --path` | Upgrade charm from local charm file |
| `jsa` | `juju scale-application` | Set the desired number of application units |
| `jssh` | `juju ssh` | Initiate an SSH session or execute a command on a Juju target |
| `jsshc` | `juju ssh --container` | Initiate an SSH session or execute a command on a given container |
| `jshu` | `juju show-unit` | Displays information about a unit |
### Storage
| Alias | Command | Description |
|---------|-------------------------------|-------------------------------------------------|
| `jrs` | `juju remove-storage` | Remove storage |
| `jrs!` | `juju remove-storage --force` | Remove storage even if it is currently attached |
### Relation
| Alias | Command | Description |
|-----------|--------------------------------|-------------------------------------------------------------------|
| `jrel` | `juju relate` | Relate two applications |
| `jrmrel` | `juju remove-relation` | Remove an existing relation between two applications. |
| `jrmrel!` | `juju remove-relation --force` | Remove an existing relation between two applications, forcefully. |
### Cross-model relation (CMR)
| Alias | Command | Description |
|----------|--------------------|----------------------------------------------------------------|
| `jex` | `juju expose` | Make an application publicly available over the network |
| `jof` | `juju offer` | Offer application endpoints for use in other models |
| `jcon` | `juju consume` | Add a remote offer to the model |
| `jrmsas` | `juju remove-saas` | Remove consumed applications (SAAS) from the model |
| `junex` | `juju unexpose` | Remove public availability over the network for an application |
### Bundle
| Alias | Command | Description |
|-------|----------------------|-------------------------------------------------------------|
| `jeb` | `juju export-bundle` | Export the current model configuration as a reusable bundle |
## Functions
- `jaddr <app_name> [unit_num]`: display app or unit IP address.
- `jreld <relation_name> <app_name> <unit_num>`: display app and unit relation data.
- `jclean`: destroy all controllers
- `jcontroller`: display the controller your are connected to.
- `jmodel`: display the model your are connected to.
- `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval
(default: 5s); you may pass additional arguments to `watch`.

View file

@ -0,0 +1,231 @@
#compdef juju
(( $+functions[compdef] )) && compdef _juju juju
# zsh completion for juju -*- shell-script -*-
__juju_debug()
{
local file="$BASH_COMP_DEBUG_FILE"
if [[ -n ${file} ]]; then
echo "$*" >> "${file}"
fi
}
__juju_help_options()
{
local out line token cleaned desc f
local -a opts pending
typeset -U opts
__juju_debug "[options] called with args: $*"
out=$(command juju help "$@" 2>/dev/null)
local rc=$?
__juju_debug "[options] juju help exit code: $rc, output length: ${#out}"
(( rc )) && return 1
while IFS= read -r line; do
if [[ "$line" =~ '^[[:space:]]{0,3}-' ]]; then
for f in "${pending[@]}"; do opts+=("$f"); done
pending=()
for token in ${(z)line}; do
cleaned="${token%%,*}"
cleaned="${cleaned%%;*}"
cleaned="${cleaned%%]*}"
cleaned="${cleaned%%)*}"
cleaned="${cleaned%%=<*}"
cleaned="${cleaned%%=*}"
cleaned="${cleaned%%<*}"
cleaned="${cleaned%%\[*}"
cleaned="${cleaned%%\(*}"
[[ "$cleaned" == --* || "$cleaned" == -[[:alnum:]] ]] || continue
[[ "$cleaned" == "-" || "$cleaned" == "--" ]] && continue
__juju_debug "[options] found flag: $cleaned"
pending+=("$cleaned")
done
elif (( ${#pending} )) && [[ -n "$line" ]]; then
desc="${line#"${line%%[![:space:]]*}"}"
desc="${desc//:/\\:}"
__juju_debug "[options] desc for ${pending[*]}: $desc"
for f in "${pending[@]}"; do opts+=("${f}:${desc}"); done
pending=()
elif [[ -z "$line" ]]; then
for f in "${pending[@]}"; do opts+=("$f"); done
pending=()
fi
done < <(printf "%s\n" "$out")
for f in "${pending[@]}"; do opts+=("$f"); done
__juju_debug "[options] total opts: ${#opts}, first few: ${opts[1]} ${opts[2]} ${opts[3]}"
printf "%s\n" "${opts[@]}"
}
__juju_help_commands()
{
local line cmd desc out
out=$(command juju help commands 2>/dev/null) || return 1
while IFS= read -r line; do
# Strip leading whitespace
line="${line#"${line%%[![:space:]]*}"}"
# Only process lines starting with an alphanumeric (command names)
[[ "$line" =~ '^[[:alnum:]]' ]] || continue
# Split on the first run of 2+ spaces: left = cmd, right = description
cmd="${line%% *}"
# Validate it's a clean command token (no spaces, only alnum and dash)
[[ "$cmd" =~ '^[[:alnum:]][[:alnum:]-]*$' ]] || continue
desc="${line#"$cmd"}"
desc="${desc#"${desc%%[![:space:]]*}"}"
if [[ -n "$desc" ]]; then
printf "%s:%s\n" "$cmd" "$desc"
else
printf "%s\n" "$cmd"
fi
done <<< "$out"
}
__juju_models()
{
# Optional argument: controller name. If given, fetch models for that controller.
if [[ -n "$1" ]]; then
command juju models -c "$1" --format=json 2>/dev/null \
| command jq -r '.models[]."short-name"' 2>/dev/null
else
command juju models --format=json 2>/dev/null \
| command jq -r '.models[]."short-name"' 2>/dev/null
fi
}
# Complete a model token that may be prefixed with "controller:" — if a colon is
# present, fetch models for that controller and offer "ctrl:model" completions.
__juju_complete_model()
{
local current="$1"
local -a completions
__juju_debug "[complete_model] current='${current}'"
if [[ "$current" == *:* ]]; then
local ctrl="${current%%:*}"
local models
models=("${(@f)$(__juju_models "$ctrl")}")
completions=("${models[@]/#/${ctrl}:}")
__juju_debug "[complete_model] ctrl=${ctrl} completions=${#completions}: ${completions[*]}"
compadd -S '' -q -- "${completions[@]}"
else
local -a models ctrls
models=("${(@f)$(__juju_models)}")
ctrls=("${(@f)$(__juju_controllers)}")
__juju_debug "[complete_model] models=${#models}: ${models[*]}"
__juju_debug "[complete_model] ctrls=${#ctrls}: ${ctrls[*]}"
__juju_debug "[complete_model] calling _alternative"
_alternative \
'models:models:{__juju_debug "[complete_model] compadd models"; compadd "$expl[@]" -a models}' \
'controllers:controllers:{__juju_debug "[complete_model] compadd ctrls"; compadd "$expl[@]" -S : -q -a ctrls}'
__juju_debug "[complete_model] _alternative returned $?"
fi
}
# Commands whose first positional argument is a model name.
_juju_model_commands=(
destroy-model
grant-model
revoke-model
switch
)
# Flags that take a model name as their value.
_juju_model_flags=(
-m
--model
)
__juju_controllers()
{
command juju controllers --format=json 2>/dev/null \
| command jq -r '.controllers | keys | .[]' 2>/dev/null
}
# Commands whose first positional argument is a controller name.
_juju_controller_commands=(
destroy-controller
kill-controller
login
logout
unregister
)
# Flags that take a controller name as their value.
_juju_controller_flags=(
-c
--controller
)
_juju()
{
__juju_debug "[_juju] curcontext: ${curcontext}"
local -a completions
__juju_debug "[_juju] words: ${words[*]}, CURRENT: $CURRENT"
# Find the subcommand: first non-flag word typed after "juju", excluding the
# word currently being completed (words[CURRENT]).
local subcmd=""
local i
for (( i = 2; i < CURRENT; i++ )); do
if [[ "${words[i]}" != -* ]]; then
subcmd="${words[i]}"
break
fi
done
local current="${words[CURRENT]}"
local prev="${words[CURRENT-1]}"
__juju_debug "[_juju] subcmd: '${subcmd}', current: '${current}', prev: '${prev}'"
# Controller name completion: flag value (e.g. juju status -c <TAB>)
if (( ${_juju_controller_flags[(I)$prev]} )); then
completions=("${(@f)$(__juju_controllers)}")
__juju_debug "[_juju] controller flag completions: ${#completions}"
(( ${#completions} )) && _describe "controller" completions && return 0
return 1
fi
# Model name completion: flag value (e.g. juju status -m <TAB> or -m ctrl:<TAB>)
if (( ${_juju_model_flags[(I)$prev]} )); then
__juju_debug "[_juju] model flag completion, current: '${current}'"
__juju_complete_model "$current" && return 0
return 1
fi
if [[ -z "$subcmd" ]]; then
# No subcommand yet — complete subcommand names.
completions=("${(@f)$(__juju_help_commands)}")
__juju_debug "[_juju] command completions count: ${#completions}"
(( ${#completions} )) && _describe "command" completions && return 0
return 1
fi
# Controller name completion: positional arg (e.g. juju destroy-controller <TAB>)
if (( ${_juju_controller_commands[(I)$subcmd]} )) && [[ "$current" != -* ]]; then
completions=("${(@f)$(__juju_controllers)}")
__juju_debug "[_juju] controller command completions: ${#completions}"
(( ${#completions} )) && _describe "controller" completions && return 0
return 1
fi
# Model name completion: positional arg (e.g. juju destroy-model <TAB> or ctrl:<TAB>)
if (( ${_juju_model_commands[(I)$subcmd]} )) && [[ "$current" != -* ]]; then
__juju_debug "[_juju] model command completion, current: '${current}'"
__juju_complete_model "$current" && return 0
return 1
fi
# Flag completion for all other subcommands (also shown without leading dash)
completions=("${(@f)$(__juju_help_options "$subcmd")}")
__juju_debug "[_juju] option completions count: ${#completions}"
(( ${#completions} )) && _describe "option" completions && return 0
return 1
}

View file

@ -0,0 +1,198 @@
# ---------------------------------------------------------- #
# Aliases and functions for juju (https://juju.is) #
# #
# Generally, #
# - `!` means --force --no-wait -y #
# - `ds` suffix means --destroy-storage #
# - `jsh` prefix means juju show-* #
# ---------------------------------------------------------- #
alias j="juju"
alias jam="juju add-model --config logging-config=\"<root>=WARNING; unit=DEBUG\"\
--config update-status-hook-interval=\"60m\""
alias jb='juju bootstrap'
alias jbng='juju bootstrap --no-gui'
alias jbl='juju bootstrap localhost'
alias jblng='juju bootstrap --no-gui localhost'
alias jbm='juju bootstrap microk8s'
alias jbmng='juju bootstrap --no-gui microk8s'
alias jc='juju config'
alias jcld='juju clouds'
alias jclda='juju clouds --all'
alias jctl='juju controllers'
alias jctlr='juju controllers --refresh'
alias jdc='juju destroy-controller --destroy-all-models'
alias 'jdc!'='juju destroy-controller --destroy-all-models --force --no-wait -y'
alias jdcds='juju destroy-controller --destroy-all-models --destroy-storage'
alias 'jdcds!'='juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y'
alias jdm='juju destroy-model'
alias 'jdm!'='juju destroy-model --force --no-wait -y'
alias jdmds='juju destroy-model --destroy-storage'
alias 'jdmds!'='juju destroy-model --destroy-storage --force --no-wait -y'
alias jde='juju deploy --channel=edge'
alias jd='juju deploy'
alias jdl='juju debug-log --ms'
alias jdlr='juju debug-log --ms --replay'
alias jcon='juju consume'
alias jeb='juju export-bundle'
alias jex='juju expose'
alias junex='juju unexpose'
alias jh='juju help'
alias jkc='juju kill-controller -y -t 0'
alias jm='juju models'
alias jmc='juju model-config'
alias jof='juju offer'
alias jra='juju run-action'
alias jraw='juju run-action --wait'
alias jrel='juju relate'
alias jrm='juju remove-application'
alias 'jrm!'='juju remove-application --force --no-wait'
alias jrmds='juju remove-application --destroy-storage'
alias 'jrmds!'='juju remove-application --destroy-storage --force --no-wait'
alias jrmrel='juju remove-relation'
alias 'jrmrel!'='juju remove-relation --force'
alias jrmsas='juju remove-saas'
alias jrp='juju refresh --path'
alias jrs='juju remove-storage'
alias 'jrs!'='juju remove-storage --force'
alias jsa='juju scale-application'
alias jsha='juju show-application'
alias jshc='juju show-controller'
alias jshm='juju show-model'
alias jshsl='juju show-status-log'
alias jshu='juju show-unit'
alias jssh='juju ssh'
alias jsshc='juju ssh --container'
alias jstj='juju status --format=json'
alias jst='juju status --relations --color'
alias jsts='juju status --relations --storage --color'
alias jsw='juju switch'
# ---------------------------------------------------------- #
# Functions (in alphabetic order) #
# ---------------------------------------------------------- #
# Get app or unit address
jaddr() {
# $1 = app name
# $2 = unit number (optional)
if (( ! ${+commands[jq]} )); then
echo "jq is required but could not be found." >&2
return 1
fi
if [[ $# -eq 1 ]]; then
# Get app address
juju status "$1" --format=json \
| jq -r ".applications.\"$1\".address"
elif [[ $# -eq 2 ]]; then
# Get unit address
juju status "$1/$2" --format=json \
| jq -r ".applications.\"$1\".units.\"$1/$2\" | .address // .\"public-address\""
else
echo "Invalid number of arguments."
echo "Usage: jaddr <app-name> [<unit-number>]"
echo "Example: jaddr karma"
echo "Example: jaddr karma 0"
return 1
fi
}
# Destroy all controllers
jclean() {
if (( ! ${+commands[jq]} )); then
echo "jq is required but could not be found." >&2
return 1
fi
local controllers=$(juju controllers --format=json | jq -r '.controllers | keys[]' 2>/dev/null)
if [[ -z "$controllers" ]]; then
echo "No controllers registered"
return 0
fi
echo "This will forcefully destroy all storages, models and controllers."
echo "Controllers to be destroyed:"
echo "$controllers"
if ! read -q '?Are you sure (y/n)? '; then
echo
echo "Aborted."
return 0
fi
echo
local controller
for controller in ${=controllers}; do
timeout 2m juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y $controller
timeout 2m juju kill-controller -y -t 0 $controller 2>/dev/null
timeout 10s juju unregister $controller 2>/dev/null
done
}
# Display app and unit relation data
jreld() {
# $1 = relation name
# $2 = app name
# $3 = unit number
if [[ $# -ne 3 ]]; then
echo "Invalid number of arguments."
echo "Usage: jreld <relation-name> <app-name> <unit-number>"
echo "Example: jreld karma-dashboard alertmanager 0"
return 1
fi
local relid="$(juju run "relation-ids $1" --unit $2/$3)"
if [[ -z "$relid" ]]; then
return 1
fi
echo "App data:"
juju run "relation-get -r $relid --app - $2" --unit $2/$3
echo
echo "Unit data:"
juju run "relation-get -r $relid - $2" --unit $2/$3
}
# Return Juju current controller
jcontroller() {
local file="${JUJU_DATA:-$HOME/.local/share/juju}/controllers.yaml"
[[ -f "$file" ]] || return 1
local controller="$(awk '/current-controller/ {print $2}' "$file")"
[[ -z "$controller" ]] && return 1
echo $controller
return 0
}
# Return Juju current model
jmodel() {
local file="${JUJU_DATA:-$HOME/.local/share/juju}/models.yaml"
[[ -f "$file" ]] || return 1
local yqbin="$(whereis yq | awk '{print $2}')"
if [[ -z "$yqbin" ]]; then
echo "--"
return 1
fi
local controller="$(jcontroller)"
local model="$(yq e ".controllers.[\"${controller}\"].current-model" < "${file}" | cut -d/ -f2)"
if [[ -z "$model" || $model == "null" ]]; then
echo "--"
return 1
fi
echo $model
return 0
}
# Watch juju status, with optional interval (default: 1 sec)
wjst() {
command -v juju >/dev/null 2>&1 || return 1
local interval="${1:-1}"
shift $(( $# > 0 ))
watch -n "$interval" --color juju status --relations --color "$@"
}