// ZSH-OPENSHIFT-ALIASES — 52 OC ALIASES + LOGIN MACROS + OC COMPLETION

zsh plugin · 52 short aliases over the OpenShift oc CLI · env-driven ocdev / ocqa login macros · auto-sourced oc tab-completion · no-op when oc is absent

GitHub Issues
// Color scheme

>_ZSH-OPENSHIFT-ALIASES

Drive your OpenShift cluster from zsh with two-to-six-character aliases. og pods instead of oc get pods, odep foo.yaml instead of oc apply -f foo.yaml, ocdev / ocqa for one-keystroke env-driven login, ologin for oc rsh into a pod. Tab-completion for oc is auto-sourced when the binary is on PATH; the whole plugin no-ops when oc is missing, so it is safe to load unconditionally.

Install

# Zinit
zinit ice lucid nocompile
zinit load MenkeTechnologies/zsh-openshift-aliases

# Oh My Zsh
git clone https://github.com/MenkeTechnologies/zsh-openshift-aliases \
    "$HOME/.oh-my-zsh/custom/plugins/zsh-openshift-aliases"
# then add zsh-openshift-aliases to plugins=(...) in ~/.zshrc

# Manual
git clone https://github.com/MenkeTechnologies/zsh-openshift-aliases
source zsh-openshift-aliases/zsh-openshift-aliases.plugin.zsh

The plugin guards on type -ap -- oc — if no oc executable is on PATH it returns immediately and registers nothing. When oc is present and the __start_oc completion function is not already defined, it runs source <(oc completion zsh) to wire up oc tab-completion.

Configuration

Three environment variables drive the login macros. The plugin initializes all three to the empty string when it sources, so set them after the plugin loads — a value exported before sourcing is overwritten on load.

OCP_USERNAMEusername passed to oc login -u by both ocdev and ocqa
OCP_DEV_URLcluster API URL ocdev logs into (e.g. https://api.dev.example.com:6443)
OCP_QA_URLcluster API URL ocqa logs into
# in ~/.zshrc, AFTER the plugin is sourced
export OCP_USERNAME='your-username'
export OCP_DEV_URL='https://api.dev.example.com:6443'
export OCP_QA_URL='https://api.qa.example.com:6443'

Login & session

ocdevoc login ${OCP_DEV_URL} -u ${OCP_USERNAME} — log into the dev cluster
ocqaoc login ${OCP_QA_URL} -u ${OCP_USERNAME} — log into the QA cluster
ologin PODoc rsh — open an interactive remote shell into a running pod

Get resources

Short reads over oc get. The -o wide variants add the extra columns (node, IP) oc hides by default.

og ARGSoc get — the base getter
odcoc get dc -o wide — deployment configs
ostsoc get sts -o wide — statefulsets
ohpaoc get hpa — horizontal pod autoscalers
opodoc get pod -o wide
osvcoc get svc -o wide
opvcoc get pvc -o wide
oisoc get is -o wide — image streams
obcoc get bc -o wide — build configs
oalloc get all -l run= — everything for a given run label
oalln APPoc get all -l run=APP -o name — names only
opodo APPoc get pod -l app=APP -o wide — pods for an app label
opd APPoc get pod -l app=APP -o jsonpath='{ .metadata.name }'
oimgoc get pods -o jsonpath='{..image}' piped through tr/sort/uniq -c — image usage tally
olcpoc get pods jsonpath dump of pod name → container images, sorted
olp APPoc get pods -o jsonpath='{..image}' -l app=APP — images for an app label

Describe, deploy, logs, copy

odesc ARGSoc describe
odhistoc rollout history dc
odep FILEoc apply -f FILE — apply a manifest
oroll DCoc rollout latest dc/DC — trigger a new rollout
orhist DCoc rollout history dc/DC
olog ARGSoc logs -f — follow logs
osync ARGSoc rsync
ocp ARGSoc cp — copy files in/out of a pod
ovoloc volume dc --all

Delete resources

odel ARGSoc delete — the base deleter
odelo KIND APPoc delete KIND -l app=APP
odela APPoc delete all -l app=APP
odeldcoc delete dc
odelstsoc delete sts
odelpodoc delete pod
odelsvcoc delete svc
odelbcoc delete bc
odelpvcoc delete pvc

Export YAML config

Each dumps a resource as YAML with --export for re-applying elsewhere.

oexp ARGSoc get ARGS -o yaml --export
opexp PODoc get pod POD -o yaml --export
odexp DCoc get dc DC -o yaml --export
osexp STSoc get sts STS -o yaml --export
ocexp CMoc get cm CM -o yaml --export — config map
ovexp PVCoc get pvc PVC -o yaml --export

Scaling

oscaled N DCoc scale --replicas=N dc DC
oscales N STSoc scale --replicas=N statefulsets STS
ostopd DCoc scale --replicas=0 dc — scale a dc to zero
ostartd DCoc scale --replicas=1 dc
ostarts STSoc scale --replicas=1 statefulsets
ostops STSoc scale --replicas=0 statefulsets

Five shell functions step replica counts by one, reading the current count via oc get ... -o jsonpath='{.spec.replicas}' then re-scaling:

oincd DC / oincs STSincrement a deployment config / statefulset replica count by 1
odecd DC / odecs STSdecrement a deployment config / statefulset replica count by 1
pod SELECTORprint the name of the running pod matching a label selector via jsonpath

Pod hygiene & backup

opcleanforce-delete every pod stuck in Terminating (--grace-period=0 --force)
opodrjsonpath list of pod names in phase Running
opodtjsonpath list of pod names in phase Terminating
obackupdump all + per-object-type YAML (rolebindings, serviceaccounts, secrets, cm, pvc, statefulsets, hpa, deployments, …) into the current directory for project backup

Workflow

# log into the dev cluster (set OCP_* first)
ocdev

# list pods with node + IP columns
opod

# tail logs of a deployment, follow
olog deployment/web

# apply a manifest
odep web.yaml

# scale a deployment config to 3, or step it up by 1
oscaled 3 web
oincd web

# remote shell into a pod
ologin web-7d9f8c-abcde

# force-clear stuck Terminating pods
opclean

Engineering report

For the full breakdown — the exact oc command each alias expands to, the load guard, the oc completion zsh sourcing, the helper-function internals, and the zunit test map — see the engineering report.

Sibling plugins

Part of the MenkeTechnologies zsh plugin family — the MenkeTechnologiesMeta umbrella: