(EDIT) For some reason I presumed this was about road bike drop-bars. MTB flat bars have other options already covered in other answers.
There exist in-line gear indicators. Shimano had one but they date from the days of gear cables coming straight out of brifters.

These cannot work with under-bartape cable routing, unless you somehow left a little window.
Model: Dura-Ace 7800, 10 speed
Rear SH81102
Front Y6JA98110
Another option is to use a brifter that has a windowed gear view. This is a 3x7, you're unlikely to find this functionality in a 12 speed brifter though maybe some of the smaller brands offer it.

A sub-variant of this might be to put a 12 speed pod shifter with a gear display indicator on your tops, and then simply use the right-hand brifter as a brake lever. Downside, your hand is off the brake while changing gear, so a bit sketchy and not ideal.
If you're all-out DI2, then its possible to add a display to the system, such as the SC-MT800 or the SC-M9050 Exact compatibility between all DI2 parts should be confirmed before purchasing.

Shimano also had a computer system called FLIGHTDECK which did exactly this using a head unit that was wired to special brifters. This one is in the little ring with the rear on the second-to-biggest cog. Suggesting the rider might be doing 38 miles/h going up a hill in 34:25. Or it's staged.

There's a surprising number of brifters out there with FLIGHT DECK sensors inside, but unlikely to be in a 12 speed model.
Lastly, don't bother. You can remember if you're in the big ring or small ring, and with modern shifters its fairly easy to get to the ends. When the shifter won't push any further, you're out of gears.