When using several toolboxes it’s hard to distinguish between them. Currently toolbox does not support setting the container hostnames and there is an open issue on Github Offer a better way to visually distinguish between containers · Issue #98 · containers/toolbox · GitHub. After following the thread i came up with a definitely not perfect solution but in the meantime it’s better than nothing.
toolbox() {
if [[ $@ =~ (enter) && ! $@ =~ (-r|--release|-d|--distro) ]]; then
CONTAINER=$(sed -E -e 's/enter|--container|-c|toolbox|\t|\n|\s//g' <<< $@)
if [[ ! -z ${CONTAINER} && ${CONTAINER} =~ "^[a-zA-Z0-9-]{1,15}$" ]]; then
command toolbox --container ${CONTAINER} run sudo hostname ${CONTAINER}
command toolbox enter ${CONTAINER}
else
command toolbox enter
fi
else
command toolbox $@
fi
}
This function can be dropped into the bashrc or zshrc and it will just override the enter
command. Suggestions to improve this snippets are welcome.