1 comment

[ 5.2 ms ] story [ 174 ms ] thread
Hello HN,

After grappling with the frustrations of manually styling long bash commands for over a decade, I finally created a tool to automate it. The motivation was simple: most DevOps professionals, like myself, document their commands. When tutorials or services (take Google Cloud Platform for instance) provide long commands on a single line, it's a legibility nightmare.

Example from GCP:

    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
After spending far too much time manually adding line breaks and styling, it would look like:

    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
This might seem trivial for one-off commands, but it quickly becomes a tedious chore with frequent DevOps tasks.

In light of this, I introduce to you, the *Bash Command Prettifier*.

All you have to do is input your lengthy bash command, and the script will automatically format it with a neat line-break after every parameter, making it easily readable and perfect for documentation.

The code is available as an open-source gist here: Bash Command Prettifier (https://gist.github.com/lucgagan/9f4219058f89c9d003ceced6d1d...)

Would love feedback, improvements, or any thoughts. If this has been a pain point for you too, hope this helps ease your DevOps documentation woes!

Test it online: https://ray.run/tools/bash-command-formatter