2cb403e89f618548b340181b5690639768305aad

Author
SpeakinTelnet <105018871+SpeakinTelnet@users.noreply.github.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(toolbox): add function to show toolbox name (#12594)

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>

Diff

 1diff --git a/plugins/toolbox/README.md b/plugins/toolbox/README.md
 2index bc04a906bd93cd8eddc66065772487d542147434..d957d9bc4cae265bb6ca751edc0ecff91554930a 100644
 3--- a/plugins/toolbox/README.md
 4+++ b/plugins/toolbox/README.md
 5@@ -10,7 +10,8 @@ plugins=(... toolbox)
 6 
 7 ## Prompt function
 8 
 9-This plugins adds `toolbox_prompt_info()` function. Using it in your prompt, it will show the toolbox indicator ⬢ (if you are running in a toolbox container), and nothing if not.
10+This plugins adds `toolbox_prompt_info()` function. Using it in your prompt, it will show the toolbox
11+indicator ⬢ (if you are running in a toolbox container), and nothing if not.
12 
13 You can use it by adding `$(toolbox_prompt_info)` to your `PROMPT` or `RPROMPT` variable:
14 
15@@ -18,9 +19,11 @@ You can use it by adding `$(toolbox_prompt_info)` to your `PROMPT` or `RPROMPT`
16 RPROMPT='$(toolbox_prompt_info)'
17 ```
18 
19+In the same way, it adds `toolbox_prompt_name()`, showing the name of the containerized environment.
20+
21 ## Aliases
22 
23-| Alias | Command              | Description                            |
24-|-------|----------------------|----------------------------------------|
25-| tbe   | `toolbox enter`      | Enters the toolbox environment         |
26-| tbr   | `toolbox run`        | Run a command in an existing toolbox   |
27+| Alias | Command         | Description                          |
28+| ----- | --------------- | ------------------------------------ |
29+| tbe   | `toolbox enter` | Enters the toolbox environment       |
30+| tbr   | `toolbox run`   | Run a command in an existing toolbox |
31diff --git a/plugins/toolbox/toolbox.plugin.zsh b/plugins/toolbox/toolbox.plugin.zsh
32index 377e498cd7af1a61a32d39f629639a527cda9919..031c0f7540a69d8e142e1043f43eaf3c4b1796a5 100644
33--- a/plugins/toolbox/toolbox.plugin.zsh
34+++ b/plugins/toolbox/toolbox.plugin.zsh
35@@ -2,5 +2,9 @@ function toolbox_prompt_info() {
36   [[ -f /run/.toolboxenv ]] && echo "⬢"
37 }
38 
39+function toolbox_prompt_name() {
40+  [[ -f /run/.containerenv ]] && cat /run/.containerenv | awk -F\" '/name/ { print$2 }'
41+}
42+
43 alias tbe="toolbox enter"
44 alias tbr="toolbox run"