Bash Command Prettifier: The Solution to Formatting Tedious, Long Commands
Tags: bash, tooling, devops
Published: 2023-09-19 21:09:23

Hello fellow DevOps enthusiasts and command-line warriors!

If you're anything like me, you value clarity and readability in your documentation. But there's a common nuisance we all face: those lengthy, unbroken bash commands. You know the ones I'm talking about. The ones that scroll endlessly, making you lose track of parameters, especially when copying them from tutorials or platforms like GCP.

**The Problem:**

Let me paint a picture:

*GCP throws at you:*
```bash
gcloud beta container --project "rayrun" node-pools create "test-runners-1" --cluster "rayrun" --zone "us-central1-c" --machine-type "e2-medium" --image-type "COS_CONTAINERD" --disk-type "pd-balanced" --disk-size "100" --metadata disable-legacy-endpoints=true --scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --num-nodes "3" --enable-autoupgrade --enable-autorepair --max-surge-upgrade 1 --max-unavailable-upgrade 0
```

*And with a sigh, you reformat it to:*

```bash
gcloud beta container \
  --project "rayrun" \
  node-pools create "test-runners-1" \
  --cluster "rayrun" \
  --zone "us-central1-c" \
  --machine-type "e2-medium" \
  --image-type "COS_CONTAINERD" \
  --disk-type "pd-balanced" \
  --disk-size "100" \
  --metadata disable-legacy-endpoints=true \
  --scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" \
  --num-nodes "3" \
  --enable-autoupgrade \
  --enable-autorepair \
  --max-surge-upgrade 1 \
  --max-unavailable-upgrade 0
```

If you are wondering, the example is taken directly from Google Cloud Platform documentation.

I found myself sinking more time into reformatting these lines than I'd like to admit. And I knew there had to be a better way.

**Introducing the Bash Command Prettifier:**

This is where the **Bash Command Prettifier** comes into play. I designed this tool to tackle this exact issue head-on. The aim? To convert tedious, single-line commands into a neatly organized, multi-line format that's both pleasant to the eye and perfect for documentation.

Simply input your marathon-length bash command, and voila! Out comes a formatted, doc-friendly version.

🌟 **Find the open-source code here**: [Bash Command Prettifier on GitHub](https://gist.github.com/lucgagan/9f4219058f89c9d003ceced6d1d544b3)

Here is an online demo: https://ray.run/tools/bash-command-formatter

**In Conclusion:**

In our fast-paced DevOps world, every second counts. Little efficiencies can make all the difference in productivity and mental well-being. My hope is that the Bash Command Prettifier serves you well and shaves precious minutes off your documentation tasks.

I'd love to hear your feedback or any suggestions for improvement. Wishing you clear and readable bash commands! Until next time. 🚀