You want to see the GNOME bug, and the corresponding two branches. Upstream of vte/Terminal don’t like the solution, but Fedora carry it as distro patches.
An added complication is that we don’t source
vte.sh on Ubuntu for non-login shells (such as those spawned by GNOME terminal/vte), so we have to find a way to do that too. When we talked about it a few years ago in the context of open-new-tab-in-the-cwd-of-current-tab (which FWIW is worked around in GNOME terminal), the bash maintainer (Matthias Klose [doko]) wasn’t happy with adding a non-login-shell equivalent. So part of this task is to speak with him and work out a solution, or otherwise find a way to get
vte.sh to be active in terminals.