A damned convenient way to get yourself dead during World War I was to pop your head up above a trench. But if you wanted to shoot the enemy, you kinda *had* to pop your head up above the trench in order to aim your rifle. Unless you had a rifle equipped with a periscope.
One such arrangement was the “Cameron Yaggi 1903 Trench Rifle” which added a complex and heavy mechanism to the 1903 Springfield rifle.The mechanism included not only a periscope and a 25-round box magazine, but additional levers to allow you to operate the bolt “remotely.” The end result is kinda spiffy, though cumbersome, and was not adopted by the US.
The modern equivalent would be to put a digital camera on the rifle, live video being directed to a eyepiece via a cable or Bluetooth.
Of course, many countries tried a similar setup. Here’s a trench Mauser that tries to do the same thing, but without the ability to work the bolt remotely.