I don’t do this anymore, as I explain a little down.

I use Toolbox a lot, like every single day. And I have a very minimal bash prompt (just $ in green and > in red for PS2). But it is quite hard to tell at a glance if I am inside a Podman container that was created by Toolbox, mostly because the tools I normally use, are there, and it’s my home directory.

I usually check /etc/fedora-release but that’s a poor check.

Well, now my prompt inside a container is different:

# Colors

# Toolbox check
if grep -q container /proc/self/cgroup; then
	export PS1="${C_PS1_CONTAINER}\h \\$ ${C_TEXT}"
	export PS1="${C_PS1}\\$ ${C_TEXT}"
export PS2="${C_PS2}> ${C_TEXT}"

That’s good enough for now.

What I do now:

Since I made this post, I realized there were some issues with the coloring in the prompt. Instead of debugging it, I changed a few things.

For starters, I keep my prompt the same everywhere and use the hostname as a way to identify where I am. So one line instead of the whole chunk before:

export PS1="\[\e[38;5;202m\]\h \[\e[38;5;131m\]\$ \[\033[0m\]"

It is not as minimal as before, but quite there.

I also use fzf keybindings which are usually not present inside a container. Instead of using the grep -q container /proc/self/cgroup approach, I just check if they are present or not:

# FZF: dnf install fzf -y
# Source only fzf bindings if the file exists. A common scenario is inside a container.
if [ -f $FZF_BINDINGS ]; then

So I guess the conclusion here is… simplifying is always better?

In any case, the original idea of detecting if you are inside a container still works:

if grep -q container /proc/self/cgroup; then
	echo "Inside a container"
	echo "Outside a container"

Now is good enough.