Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to show the context in the user's prompt #806

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion docs/quickstart/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -317,6 +318,59 @@ 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"
# 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 $ _
```

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"
# 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 $ _
```

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 '$ '
$ _ <my-org:my-project:my-space>
```

### Plugins can also be discovered and installed when connecting to a Context

Switching to another context:
Expand Down
Loading