From b1f573fd9cdaf716309f0e33f1472b832eaa3082 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 5 Sep 2024 16:26:09 -0400 Subject: [PATCH 1/2] Document how to show the context in the prompt Signed-off-by: Marc Khouzam --- docs/quickstart/quickstart.md | 42 ++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/quickstart/quickstart.md b/docs/quickstart/quickstart.md index 954501943..6bf3ec6a3 100644 --- a/docs/quickstart/quickstart.md +++ b/docs/quickstart/quickstart.md @@ -258,7 +258,8 @@ endpoint to the Tanzu Mission Control service, or providing a kubeconfig to an existing Tanzu Cluster as shown above. Note: The `tanzu context current --short` command prints a compact form of the current context. This can be used -in prompts to help users keep track of which context the tanzu CLI is currently interacting with. +in prompts to help users keep track of which context the tanzu CLI is currently interacting with. Some examples +are shown [in a section below](#including-context-information-in-your-prompt). #### Creating a Tanzu Context @@ -317,6 +318,45 @@ reference for more detail. Other plugins, such as the Tanzu `management-cluster` plugin, can create a context as part of creating a Tanzu cluster. +#### Including context information in your prompt + +Here are a few examples of how to add the context information to your prompt. +You can easily adapt these examples to your own taste. + +Prefixing the existing main prompt: + +```console +# bash +PS1="$(tanzu context current --short) $PS1" +# zsh +PROMPT="$(tanzu context current --short) $PROMPT" + +# Example result for a main prompt that was '$ ' +my-org:my-project:my-space $ _ +``` + +Prefixing the existing main prompt but not showing the org-name: + +```console +# bash +PS1="$(tanzu context current --short | cut -d: -f2-) $PS1" +# zsh +PROMPT="$(tanzu context current --short | cut -d: -f2-) $PROMPT" + +# Example result for a main prompt that was '$ ' +my-project:my-space $ _ +``` + +Setting the reverse prompt (not available for `bash`): + +```console +# zsh +RPROMPT="<$(tanzu context current --short)>" + +# Example result for a main prompt that was '$ ' +$ _ +``` + ### Plugins can also be discovered and installed when connecting to a Context Switching to another context: From 37b764dc60504ef68aa836061af704ffdfc04718 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 5 Sep 2024 16:52:09 -0400 Subject: [PATCH 2/2] Instructions for prompt for fish shell Signed-off-by: Marc Khouzam --- docs/quickstart/quickstart.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/quickstart/quickstart.md b/docs/quickstart/quickstart.md index 6bf3ec6a3..3bd3a2032 100644 --- a/docs/quickstart/quickstart.md +++ b/docs/quickstart/quickstart.md @@ -330,6 +330,11 @@ Prefixing the existing main prompt: PS1="$(tanzu context current --short) $PS1" # zsh PROMPT="$(tanzu context current --short) $PROMPT" +# fish +functions --copy fish_prompt fish_prompt_ori +function fish_prompt + echo "$(tanzu context current --short) $(fish_prompt_ori)" +end # Example result for a main prompt that was '$ ' my-org:my-project:my-space $ _ @@ -342,6 +347,11 @@ Prefixing the existing main prompt but not showing the org-name: PS1="$(tanzu context current --short | cut -d: -f2-) $PS1" # zsh PROMPT="$(tanzu context current --short | cut -d: -f2-) $PROMPT" +# fish +functions --copy fish_prompt fish_prompt_ori +function fish_prompt + echo "$(tanzu context current --short | cut -d: -f2-) $(fish_prompt_ori)" +end # Example result for a main prompt that was '$ ' my-project:my-space $ _ @@ -352,6 +362,10 @@ Setting the reverse prompt (not available for `bash`): ```console # zsh RPROMPT="<$(tanzu context current --short)>" +# fish +function fish_right_prompt + echo "<$(tanzu context current --short)>" +end # Example result for a main prompt that was '$ ' $ _