Sunday, 26 October 2025

shellcommand | shellcommand | pbcopy aliases FTW

This is such a simple yet powerful thing. I was writing up a slightly-tedious process at work that required using various command-line tools (like `kubectl`) to access a secret being used in a Kubernetes pod. The secret could then be copy-pasted into a web UI that needed access using the same credentials. That's when it hit me: the whole thing can be done as a one-liner that finishes with ` | pbcopy` to paste the output into the clipboard, and then aliased in your shell startup (e.g. `~/.zprofile` on the Mac); e.g.: ``` alias getdbpass="kubectl get secret db_secrets-collection -n namespace -o json | jq --raw-output '\''.data | map_values(@base64d) | .PASSWORD'\'' | pbcopy' ``` Now you just type `getdbpass` when you need to get in, flip to your browser, and Cmd-V. And you can always check/remind yourself what it does with `alias` on the command line. You can build up an awesome collection of these. saving time and typos - give it a try!

No comments:

Post a Comment

Comments welcome - spam is not. Spam will be detected, deleted and the source IP blocked.