Created
January 8, 2026 09:12
-
-
Save hermannolafs/c31d9c4e3c9c913ccd69fd55401393db to your computer and use it in GitHub Desktop.
fish function to run get the state paths in the plan output with a rainbow colour 🐬
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function tf_plan_rainbow | |
| tofu plan | grep "# module" | awk ' | |
| BEGIN { | |
| # bold: red, green, yellow, blue, magenta, cyan | |
| colors[0] = "\033[1;31m"; colors[1] = "\033[1;32m"; colors[2] = "\033[1;33m"; | |
| colors[3] = "\033[1;34m"; colors[4] = "\033[1;35m"; colors[5] = "\033[1;36m"; | |
| reset = "\033[0m"; | |
| } | |
| { | |
| line = $0; | |
| # preserve leading "# " (and any indent) uncolored | |
| prefix = ""; rest = line; | |
| if (match(line, /^[[:space:]]*# /)) { | |
| prefix = substr(line, 1, RLENGTH); | |
| rest = substr(line, RLENGTH + 1); | |
| } | |
| # split off the suffix starting at " will be " (leave it uncolored) | |
| path = rest; suffix = ""; | |
| if (match(rest, / will be /)) { | |
| path = substr(rest, 1, RSTART - 1); | |
| suffix = substr(rest, RSTART); | |
| } | |
| # colorize each dot-delimited segment | |
| n = split(path, segs, /\./); | |
| out = ""; | |
| for (i = 1; i <= n; i++) { | |
| c = colors[(i - 1) % 6]; | |
| if (i > 1) out = out "."; | |
| out = out c segs[i] reset; | |
| } | |
| print prefix out suffix; | |
| }' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment