-
Notifications
You must be signed in to change notification settings - Fork 220
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
Expose the name of the current toolbox container #744
Comments
In case anyone else stumbles across this looking for a copy+paste solution before this becomes a proper feature in Toolbox, here is what I added to my if [ -f "/run/.containerenv" ]; then
TOOLBOX_NAME=[$(cat /run/.containerenv | grep 'name=' | sed -e 's/^name="\(.*\)"$/\1/')]
else
TOOLBOX_NAME=""
fi It can then be used within the |
My starship config can be used with any shell to get container name. format = """${custom.toolbox}$directory$git_branch$git_metrics$git_status$dotnet$character"""
[custom.toolbox]
command = """ grep -Po 'name="\\K[^"]+' /run/.containerenv """
files = [ "/run/.containerenv" ]
when = "test -f /run/.containerenv"
style = "bg:bright-blue black"
format = "[ $output ]($style)" |
I ended up putting this in #!/usr/bin/env bash
set -Eeuo pipefail
declare -r containerenvpath='/run/.containerenv'
if [ -r $containerenvpath ]; then
source $containerenvpath
printf '%s' "$name"
else
exit 1
fi |
Oops! I have no idea how I managed to miss this issue for so long.
Yes, please do continue to parse In containers/podman#6192 I had requested for the metadata that shows up in The format of You can also get the same metadata through I don't want to add yet another way to access that metadata to Toolbx, because it will be a duplicated interface that we will have to maintain, write tests that get executed on every CI run, etc.. Instead let's just rely on the existing mechanisms. That said, if the existing mechanisms don't work for some use-case, then please do file a new issue with details. |
Closing. Thanks for playing with Toolbx and sharing those interesting snippets. :) |
Is your feature request related to a problem? Please describe.
I want to display the name of the toolbox I'm currently in in my prompt, or in my tmux bar, without relying on the container engine underlying Toolbox.
Describe the solution you'd like
While there is an open issue specifically targeting the stock Bash
$PS1
, I'd fancy a backend-agnostictoolbox
command that just outputs the current toolbox name. The reason for this is: I use a customised command prompt and I use ZSH.Here's a proposal:
Basically,
toolbox show
outputs the value of/run/.containerenv
'sname
.The command exits with 1 if the current shell is not running in a toolbox.
Describe alternatives you've considered
toolbox list --current
toolbox show <toolbox>
outputs some interesting info on the container in a machine-readable format, and defaults to the current toolbox (errors if not in a toolbox, and<toolbox>
is not passed)/run/.containerenv
.Additional context
Depends on containers/podman#6192
The text was updated successfully, but these errors were encountered: