ccloud prompt
Description
Use this command to add ccloud information in your terminal prompt.
For Bash, you’ll want to do something like this:
export PS1="\$(ccloud prompt) $PS1"
ZSH users should be aware that they will have to set the ‘PROMPT_SUBST’ option first:
setopt prompt_subst
export PS1="\$(ccloud prompt) $PS1"
You can customize the prompt by calling passing a ‘–format’ flag, such as ‘-f “ccloud|%E:%K”’.
If you want to create a more sophisticated prompt (such as using the built-in color functions),
it’ll be easiest for you if you use an environment variable rather than try to escape the quotes.
export {{.CLIName | ToUpper}}_PROMPT_FMT='({{"{{"}}color "blue" "ccloud"{{"}}"}}|{{"{{"}}color "red" "%E"{{"}}"}}:{{"{{"}}color "cyan" "%K"{{"}}"}})'
export PS1="\$(ccloud prompt -f '${{.CLIName | ToUpper}}_PROMPT_FMT') $PS1"
To make this permanent, you must add it to your bash or zsh profile.
Colors
There are special functions used for controlling colors.
- {{“{{“}}color “<color>” “some text”{{“}}”}}
- {{“{{“}}fgcolor “<color>” “some text”{{“}}”}}
- {{“{{“}}bgcolor “<color>” “some text”{{“}}”}}
- {{“{{“}}colorattr “<attr>” “some text”{{“}}”}}
Available colors: black, red, green, yellow, blue, magenta, cyan, white
Available attributes: bold, underline, invert (swaps the fg/bg colors)
Examples:
- {{“{{“}}color “red” “some text” | colorattr “bold” | bgcolor “blue”{{“}}”}}
- {{“{{“}}color “red”{{“}}”}} some text here {{“{{“}}resetcolor{{“}}”}}
You can also mix format tokens and/or data in the same line
* {{“{{“}}color “cyan” “%E”{{“}}”}} {{“{{“}}color “blue” .KafkaClusterId{{“}}”}}
Notes:
- ‘color’ is just an alias of ‘fgcolor’
- calling ‘resetcolor’ will reset all color attributes, not just the most recently set
You can disable color output by passing the flag ‘–no-color’.
Flags
-f, --format string The format string to use. See the help for details. (default "({{color \"blue\" \"ccloud\"}}|{{color \"red\" \"%E\"}}:{{color \"cyan\" \"%K\"}})")
-g, --no-color Do not include ANSI color codes in the output.
-t, --timeout string The maximum execution time in milliseconds. (default "200ms")
Global Flags
-h, --help Show help for this command.
-v, --verbose count Increase verbosity (-v for warn, -vv for info, -vvv for debug, -vvvv for trace).