Everyone expected Oracle Cloud Infrastructure (OCI) to refine its command-line interface. It’s been a slow march, frankly. The constant --compartment-id requirement alone was a developer’s lament. But the real migraine? Managing multiple tenancies. Prod, staging, dev, clients — each a different --profile, each a distinct --compartment-id. Passing them all, on every single command? Utterly brutal. This changes things.
No one asked for this particular brand of suffering. But it happened. And the OCI CLI, bless its opaque little heart, just kept demanding more. More context. More flags. More tedious typing that eats away at your soul, one character at a time. Then, someone, somewhere, decided enough was enough.
Is This the OCI CLI Rescue You’ve Been Waiting For?
Enter ocswitch. It’s not exactly groundbreaking tech. It’s a set of shell functions. But for anyone drowning in OCI’s multi-tenancy chaos, it’s a life raft. The problem is simple: the OCI CLI’s default config mechanism is… anemic. You can point it to different config files via OCI_CONFIG_FILE, and select profiles with OCI_CLI_PROFILE. That’s it. The official tooling’s solution for multiple profiles is stuffing them all into one file and demanding you remember --profile every. single. time. Forget, and you’re back to whatever profile sits in [DEFAULT]. Worse, these are session-scoped. Open a new terminal, and your carefully selected profile vanishes.
ocswitch fixes this. How? It’s elegantly crude. It writes your active profile to a persistent file, ~/.oci/active_profile. Then, it makes sure your shell sources this state on startup. Profiles themselves aren’t crammed into one file; they’re separate files in ~/.oci/, like config_prod, config_staging, etc. To switch, you just type ocswitch prod. Boom. That file ~/.oci/active_profile gets updated. Your OCI_CONFIG_FILE and OCI_CLI_PROFILE env vars are set for the current shell. Every subsequent oci command? It’s pointed at your chosen tenancy. No more forgetting.
This persistence is key. Your chosen profile follows you. Across terminals. Across reboots. It’s the kind of small thing that makes a massive difference when you’re living in the CLI.
The multi-profile story in the official tooling is basically: put multiple
[PROFILE_NAME]sections in one config file and pass--profile PROFILE_NAMEevery time. If you forget the flag, you hit whichever profile is in[DEFAULT]. This works but it is tedious, and it is session-scoped - export the env var in one terminal, open another, you are back to default.
So, What Else Does ocswitch Do?
It’s not just about switching. There’s ocswitch list. It scans ~/.oci/config_* and shows you what you have, highlighting the active one. It’s a nice touch. It even gives you tab completion. For bash and zsh. So you can type ocswitch <tab> and see list, clear, and all your profile names. Finally, a bit of sanity.
And then there’s ocid. This is genuinely useful. It reads your active config, pulls out the tenancy OCID and user OCID, and then calls the OCI IAM API to resolve them into human-readable names. Tenant Name. Tenant ID. User Email. Crucial when you’re neck-deep in multiple accounts and need absolute certainty before you hit that delete button. It’s a safety net. A very necessary one.
Installation is straightforward. Download a script for your shell (bash or zsh) into ~/.oci/ and source it in your .bashrc or .zshrc. That’s it. No complex dependencies. Just the OCI CLI itself, and a bit of shell scripting magic.
Oracle’s own tooling has always felt like a work-in-progress, especially around basic usability for power users. The --compartment-id on every command, the convoluted multi-profile setup – it screams “we built the backend first, and the developer experience is an afterthought.” Tools like ocswitch are the community stepping in to fill the gaping holes. It’s a shame Oracle doesn’t bake this level of usability into their official CLI from the start. But, beggars can’t be choosers, can they? This ocswitch utility is a welcome relief for anyone who spends their days wrestling with OCI. It’s a small tool, but it solves a significant pain point. Consider it the indispensable duct tape for your OCI CLI workflow.
🧬 Related Insights
- Read more: [Git Data] 8 Commands Developers Actually Use Daily
- Read more: NestJS i18n Goes Vietnamese: Beyond English/Spanish [DevTools Feed]
Frequently Asked Questions
What does ocswitch actually do?
ocswitch is a set of shell functions designed to simplify managing multiple Oracle Cloud Infrastructure (OCI) profiles and tenancies via the OCI CLI. It allows you to easily switch between different OCI configurations, persists your selection across terminal sessions, and provides helpful utilities like listing available profiles and displaying tenancy information.
Will ocswitch work on Windows?
ocswitch is designed for Unix-like shells (bash and zsh) and is typically installed on Linux or macOS systems. It’s not directly compatible with the native Windows Command Prompt or PowerShell without a compatibility layer like Windows Subsystem for Linux (WSL).
Does ocswitch require the OCI CLI to be installed?
Yes, ocswitch relies on the OCI CLI being installed and configured on your system. It modifies environment variables and uses the OCI CLI’s configuration files to function.